Page 1 of 1

strtotime() problems...

Posted: Mon Mar 05, 2007 4:59 am
by dhrosti
Im having trouble trying to convert DD-MM-YYYY to a timestamp using strtotime().

Is there a way of telling the function what the date format is that im giving to it?

I think its getting confused as to wether im giving it dd-mm-yyyy or mm-dd-yyyy.

Posted: Mon Mar 05, 2007 5:26 am
by volka
What's the source of this DD-MM-YYYY datestring?

Posted: Mon Mar 05, 2007 5:42 am
by dhrosti
Its a user input. I though it would be more straight forward for the user to input the date in the format they're used to. Im currently looking at explode() and mktime() which looks like it could work.

Posted: Mon Mar 05, 2007 5:54 am
by dude81
I'm sure explode and mktime will help you as I did it once when I didn't use any library of date. There is also an alternative. You can use PEAR:DATE library which is quiet easy to use.

Posted: Mon Mar 05, 2007 6:10 am
by volka
I'm used to dd.mm.yyyy or mm/dd/yyyy or yyyy-mm-dd and so is strtotime.
Who's used to dd-mm-yyyy? (Real question, I honestly don't know)

Posted: Mon Mar 05, 2007 6:30 am
by Kieran Huggins
mm-dd-yyyy is the UK/Cdn standard I believe, which is why strtotime is getting confused. Maybe you could preg_replace() it on the way in?

Posted: Mon Mar 05, 2007 7:51 am
by dhrosti

Code: Select all

// For example, 23rd Jan 2006...
$date = "23-01-2006";
$comp = explode("-", $date);
$time = mktime(12, 0, 0, $comp[1], $comp[0], $comp[2]);
It works, but is this not a good way of doing it?

Posted: Mon Mar 05, 2007 8:19 am
by volka
I still believe it's unnecessary ;) Who's used to dd-mm-yyyy?

Posted: Mon Mar 05, 2007 8:22 am
by dhrosti
Not sure really, the boss just decided to do it like that.

Posted: Mon Mar 05, 2007 8:29 am
by feyd
I'd suggest using a date picker over attempting to handle user input such as that. There are just too many combinations otherwise.