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"; Quote 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"; ?> Quote 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". Quote 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() Quote 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"; ?> Quote 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? Quote 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 Quote 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? Quote 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 Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/156883-solved-simple-strtotime-error/#findComment-826489 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.