PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
dhrosti
Forum Commoner
Posts: 90 Joined: Wed Jan 10, 2007 5:01 am
Location: Leeds, UK
Post
by dhrosti » Mon Mar 05, 2007 4:59 am
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Mar 05, 2007 5:26 am
What's the source of this DD-MM-YYYY datestring?
dhrosti
Forum Commoner
Posts: 90 Joined: Wed Jan 10, 2007 5:01 am
Location: Leeds, UK
Post
by dhrosti » Mon Mar 05, 2007 5:42 am
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.
dude81
Forum Regular
Posts: 509 Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City
Post
by dude81 » Mon Mar 05, 2007 5:54 am
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.
Last edited by
dude81 on Mon Mar 05, 2007 6:16 am, edited 1 time in total.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Mar 05, 2007 6:10 am
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)
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Mon Mar 05, 2007 6:30 am
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?
dhrosti
Forum Commoner
Posts: 90 Joined: Wed Jan 10, 2007 5:01 am
Location: Leeds, UK
Post
by dhrosti » Mon Mar 05, 2007 7:51 am
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?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Mar 05, 2007 8:19 am
I still believe it's unnecessary
Who's used to dd-mm-yyyy?
dhrosti
Forum Commoner
Posts: 90 Joined: Wed Jan 10, 2007 5:01 am
Location: Leeds, UK
Post
by dhrosti » Mon Mar 05, 2007 8:22 am
Not sure really, the boss just decided to do it like that.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Mar 05, 2007 8:29 am
I'd suggest using a date picker over attempting to handle user input such as that. There are just too many combinations otherwise.