Welcome to WebmasterWorld Guest from 184.73.3.107

Forum Moderators: coopster & jatar k

Can't work out what's going on with dates?

dd/mm/yy -> mm/dd/yy?

   
2:35 am on Oct 2, 2006 (gmt 0)

10+ Year Member



Hello

I'm trying to format some user input of dates.

I am using PHP 4.4.2

Running this


<?
$fred = strftime("%d/%m/%y",strtotime('11/12/07'));
echo "$fred";
?>

produces:


12/11/07

I am going nuts with this

Please help

3:06 am on Oct 2, 2006 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

setlocale
to modify the locale used by the script.
3:16 am on Oct 2, 2006 (gmt 0)

10+ Year Member



Thanks DrDoc

(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

4:03 am on Oct 2, 2006 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



strtotime [php.net]
The function expects to be given a string containing a US English date format...

See also Date Input Formats [gnu.org], which is what

strtotime
follows.
4:04 am on Oct 2, 2006 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Since it's user input -- perhaps you should use dropdowns to select days/months?
5:15 am on Oct 2, 2006 (gmt 0)

10+ Year Member



Thanks. Will use dropdowns.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month