elmas156 Posted September 24, 2008 Share Posted September 24, 2008 I'm trying to get a unix timestamp of a previous date and the current date so that I can compare them in a script that I'm writing. I've tried the following code in several variations but the output for the $now and $then variables are always the same, which is the current unix timestamp. What am I doing wrong? Here's my code: <?php $apptdate="2008-09-20"; $now = time(); $then = time("$apptdate"); echo "$now<br>"; echo "$then"; ?> Quote Link to comment Share on other sites More sharing options...
jonsjava Posted September 24, 2008 Share Posted September 24, 2008 try this: <?php $apptdate="2008-09-20"; $now = time(); $then = time() - 86400; //current time minus 1 day echo "$now<br>"; echo "$then"; ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 ...jonsjava, that doesn't use $apptdate though. =/ Try: <?php $apptdate="2008-09-20"; $now = time(); $then = strtotime($apptdate); echo "$now<br>"; echo "$then"; ?> Quote Link to comment Share on other sites More sharing options...
jonsjava Posted September 24, 2008 Share Posted September 24, 2008 doh! didn't read his post correctly. Quote Link to comment Share on other sites More sharing options...
elmas156 Posted September 24, 2008 Author Share Posted September 24, 2008 that works for $then but now how do I get the timestamp for the current date at exactly midnight? I need this so I can do something like this: <?php if ($then == $now - 7776000) { // if $then is 90 days ago send a reminder email } Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 $midnight = strtotime('midnight'); I love strtotime(). Quote Link to comment Share on other sites More sharing options...
elmas156 Posted September 24, 2008 Author Share Posted September 24, 2008 GREAT! Thanks. Quote Link to comment Share on other sites More sharing options...
discomatt Posted September 24, 2008 Share Posted September 24, 2008 Slightly faster mktime(23,59,59) Technically, 24:00:00 is 00:00:00 of the next day. if you want that just use mktime(24,0,0) Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 strtotime() makes the world go 'round though... =( Quote Link to comment Share on other sites More sharing options...
elmas156 Posted September 24, 2008 Author Share Posted September 24, 2008 One more question... how do I take the timestamp and convert it back to a normal date? convert 1222326000 to 2008-09-24 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 $date = date('Y-m-d', $timestamp); Quote Link to comment Share on other sites More sharing options...
elmas156 Posted September 24, 2008 Author Share Posted September 24, 2008 thanks again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.