View Full Version : PHP Dates
Timer
03-28-2009, 05:03 AM
Ok... pretend the account timer was made.... (m-d-Y format)
03-20-2009
if the account has been made for more then 30 days... then have a function return the word "done" ... if its not been 30 days... have it return the remaining days till 30 days is up.. is that too hard to ask? :redface:
and can it read the dates from a array please? like
"Timer" => "03-20-2009"
"Hexinist" => "03-21-2009"
Code pl0x? I've tried and failed.. thanks in advance!
nielsie95
03-28-2009, 08:27 AM
<?php
$arr["Timer"] = "03-20-2009";
$arr["Hexinist"] = "03-21-2009";
$arr["nielsie95"] = "02-21-2009";
foreach ($arr as $name => $d) {
$ardate = explode("-", $d);
$tdate = mktime(0, 0, 0, $ardate[0], $ardate[1], $ardate[2]);
$togo = 30 - floor((time() - $tdate) / (60 * 60 * 24));
echo "$name => ".(($togo <= 0) ? "done" : "$togo days to go")."<br \>\n";
}
?>
Bobarkinator
03-28-2009, 09:06 AM
wow looks like PHP tags need some work.
Wizzup?
03-28-2009, 01:20 PM
wow looks like PHP tags need some work.
Blame GeSHi, but I recon I can fix it myself.
Bobarkinator
03-28-2009, 04:51 PM
Blame GeSHi, but I recon I can fix it myself.
Weird, I thought GeShi was pretty stable, no?
Timer
03-30-2009, 12:38 AM
<?php
$arr["Timer"] = "03-20-2009";
$arr["Hexinist"] = "03-21-2009";
$arr["nielsie95"] = "02-21-2009";
foreach ($arr as $name => $d) {
$ardate = explode("-", $d);
$tdate = mktime(0, 0, 0, $ardate[0], $ardate[1], $ardate[2]);
$togo = 30 - floor((time() - $tdate) / (60 * 60 * 24));
echo "$name => ".(($togo <= 0) ? "done" : "$togo days to go")."<br \>\n";
}
?>
Thanks! :D
Edit..
I modified it a bit..
Now I'm getting..
Warning: mktime() expects parameter 4 to be long, string given in /home/mgate3/public_html/timer/bypass/includes.php on line 7
from this code
<?php
$arr["Timer"] = "03-20-2009";
$arr["Hexinist"] = "03-21-2009";
function DaysLeft($name) {
$ardate = explode("-", $arr[$name]);
$tdate = mktime(0, 0, 0, $ardate[0], $ardate[1], $ardate[2]);
$togo = 30 - floor((time() - $tdate) / (60 * 60 * 24));
if (togo <= 0) {
return "done";
exit;
} else {
return $togo;
}
}
echo DaysLeft("Timer");
?>
nielsie95
03-30-2009, 06:59 AM
You can't access the array inside the function..
function DaysLeft($name, $arr) {
$ardate = explode("-", $arr[$name]);
$tdate = mktime(0, 0, 0, $ardate[0], $ardate[1], $ardate[2]);
$togo = 30 - floor((time() - $tdate) / (60 * 60 * 24));
if (togo <= 0) {
return "done";
exit;
} else {
return $togo;
}
}
echo DaysLeft("Timer", $arr);
Timer
03-30-2009, 08:09 PM
oh, lol, thanks! :D
EDIT -
Now.. its really messed up.. no matter what, it returns done..
<?php
$arr["Timer"] = "03-10-2009";
$arr["Hexinist"] = "03-21-2009";
function DaysLeft($name, $arr) {
$ardate = explode("-", $arr[$name]);
$tdate = mktime(0, 0, 0, $ardate[0], $ardate[1], $ardate[2]);
$togo = 30 - floor((time() - $tdate) / (60 * 60 * 24));
if (togo <= 0) {
return "done";
} else {
return $togo;
}
}
echo DaysLeft("Timer", $arr);
?>
nielsie95
03-31-2009, 01:29 PM
How long did you try it for yourself..? :\
if ($togo <= 0) {
Timer
03-31-2009, 08:35 PM
lol, wow.. i totally didn't notice that... :o
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.