Welcome to WebmasterWorld Guest from 126.96.36.199 , register , free tools , login , search , pro membership , help , library , announcements , recent posts , open posts Pubcon Platinum Sponsor 2014
Can't work out what's going on with dates? dd/mm/yy -> mm/dd/yy? Kenton
I'm trying to format some user input of dates.
I am using PHP 4.4.2
<? $fred = strftime("%d/%m/%y",strtotime('11/12/07')); echo "$fred"; ?>
I am going nuts with this
I take it you want to use Dec 11. Well, if so -- it's best to always use ISO dates, until they are printed. Using a non-ISO date means that you have to worry about locales and other such things, which is what you are running into here. You are passing "11/12/07" ... obviously meaning "11 December, 2007" ... But, due to the server locale, it will treat it as "November 12, 2007". Using an ISO date solves this:
$fred = strftime("%d/%m/%y",strtotime('2007-12-11')); echo "$fred"; ?>
OR, prior to the "strtotime" line -- use
to modify the locale used by the script. Kenton
(yes I did mean December)
But ... already tried setlocale
<? setlocale (LC_TIME, 'en_GB'); $fred = strftime("%d/%m/%y",strtotime('11/12/07')); echo "$fred"; ?>
produces the same result.
Also, as this is user input, I would prefer to stick to the common dd/mm/yy format.
thanks for any help
strtotime [ php.net]
The function expects to be given a string containing a US English date format...
Date Input Formats [ gnu.org], which is what
Since it's user input -- perhaps you should use dropdowns to select days/months? Kenton
Thanks. Will use dropdowns.