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"; ?> Link to comment https://forums.phpfreaks.com/topic/125648-solved-time-function-help-please/ 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"; ?> Link to comment https://forums.phpfreaks.com/topic/125648-solved-time-function-help-please/#findComment-649649 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"; ?> Link to comment https://forums.phpfreaks.com/topic/125648-solved-time-function-help-please/#findComment-649652 Share on other sites More sharing options...
jonsjava Posted September 24, 2008 Share Posted September 24, 2008 doh! didn't read his post correctly. Link to comment https://forums.phpfreaks.com/topic/125648-solved-time-function-help-please/#findComment-649653 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 } Link to comment https://forums.phpfreaks.com/topic/125648-solved-time-function-help-please/#findComment-649658 Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 $midnight = strtotime('midnight'); I love strtotime(). Link to comment https://forums.phpfreaks.com/topic/125648-solved-time-function-help-please/#findComment-649663 Share on other sites More sharing options...
elmas156 Posted September 24, 2008 Author Share Posted September 24, 2008 GREAT! Thanks. Link to comment https://forums.phpfreaks.com/topic/125648-solved-time-function-help-please/#findComment-649686 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) Link to comment https://forums.phpfreaks.com/topic/125648-solved-time-function-help-please/#findComment-649687 Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 strtotime() makes the world go 'round though... =( Link to comment https://forums.phpfreaks.com/topic/125648-solved-time-function-help-please/#findComment-649691 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 Link to comment https://forums.phpfreaks.com/topic/125648-solved-time-function-help-please/#findComment-649724 Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 $date = date('Y-m-d', $timestamp); Link to comment https://forums.phpfreaks.com/topic/125648-solved-time-function-help-please/#findComment-649732 Share on other sites More sharing options...
elmas156 Posted September 24, 2008 Author Share Posted September 24, 2008 thanks again! Link to comment https://forums.phpfreaks.com/topic/125648-solved-time-function-help-please/#findComment-649743 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.