kernelgpf Posted May 5, 2009 Share Posted May 5, 2009 The code: $today=date('m/d/y'); $time="6 MONTHS"; $expires=date("$today", strtotime("+$time")); print "$today and $expires"; Prints out "05/04/09 and 05/04/09"; Link to comment https://forums.phpfreaks.com/topic/156883-solved-simple-strtotime-error/ Share on other sites More sharing options...
RussellReal Posted May 5, 2009 Share Posted May 5, 2009 <?php $today=date('m/d/y'); $time="6 MONTHS"; $expires = strtotime("$today + $time"); print "$today and $expires"; ?> Link to comment https://forums.phpfreaks.com/topic/156883-solved-simple-strtotime-error/#findComment-826440 Share on other sites More sharing options...
kernelgpf Posted May 5, 2009 Author Share Posted May 5, 2009 "05/04/09 and 1257318000". Link to comment https://forums.phpfreaks.com/topic/156883-solved-simple-strtotime-error/#findComment-826445 Share on other sites More sharing options...
RussellReal Posted May 5, 2009 Share Posted May 5, 2009 use $expires in date() Link to comment https://forums.phpfreaks.com/topic/156883-solved-simple-strtotime-error/#findComment-826452 Share on other sites More sharing options...
Maq Posted May 5, 2009 Share Posted May 5, 2009 You need to give date it's first formatting parameter: $today=date('m/d/y'); $time="6 MONTHS"; $expires = date('m/d/y', strtotime("$today + $time")); print "$today and $expires"; ?> Link to comment https://forums.phpfreaks.com/topic/156883-solved-simple-strtotime-error/#findComment-826453 Share on other sites More sharing options...
kernelgpf Posted May 5, 2009 Author Share Posted May 5, 2009 A step better: $today=date('d/m/y'); $time="6 MONTHS"; $expires = date('d/m/y', strtotime("$today + $time")); print "$today and $expires"; But now it prints out "04/05/09 and 05/10/09". It thinks today is April 5th? Link to comment https://forums.phpfreaks.com/topic/156883-solved-simple-strtotime-error/#findComment-826456 Share on other sites More sharing options...
kenrbnsn Posted May 5, 2009 Share Posted May 5, 2009 You formated the date as "day/month/year" so "04/05/09" is the 4th of May. If you want "month/day/year" use "m/d/y". Read the manual entry for date. Ken Link to comment https://forums.phpfreaks.com/topic/156883-solved-simple-strtotime-error/#findComment-826460 Share on other sites More sharing options...
kernelgpf Posted May 5, 2009 Author Share Posted May 5, 2009 Oh, duh. Sorry. But that's only 5 months, not 6? Link to comment https://forums.phpfreaks.com/topic/156883-solved-simple-strtotime-error/#findComment-826462 Share on other sites More sharing options...
kenrbnsn Posted May 5, 2009 Share Posted May 5, 2009 No, it's 6 months -- June 5th, July 5th, August 5th, September 5th, October 5th, November 5th. Ken Link to comment https://forums.phpfreaks.com/topic/156883-solved-simple-strtotime-error/#findComment-826469 Share on other sites More sharing options...
Ken2k7 Posted May 5, 2009 Share Posted May 5, 2009 Oh, duh. Sorry. But that's only 5 months, not 6? Understandably, you're thinking of that because you formatted your date wrong. $today=date('m/d/y'); $time="6 MONTHS"; $expires = date('m/d/y', strtotime("$today + $time")); echo "$today and $expires"; See what that echos out. It should look right to you. Link to comment https://forums.phpfreaks.com/topic/156883-solved-simple-strtotime-error/#findComment-826489 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.