Jump to content

strtotime Questions


TeddyKiller

Recommended Posts

DD-MM-YYYY (01-04-2010)

MM-DD-YYYY (04-01-2010)

 

+ Other ways of formating date and time.

 

I believe strtotime() would give those dates a different timestamp as the format isn't defined.

 

How could I work around it? It's part of form validation.. so by this point, nothing is inserted into the database.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/202116-strtotime-questions/
Share on other sites

well what are you ultimately putting into your database, a timestamp of the date the user enters in?  Sure, you can use mktime but if you already have the fields separated and know which values are for what, you can use strtotime just the same..., since you control the format being handed to it...

 

edit:

strtime attempts to parse the string, and it recognizes a lot of formats, but if you are unsure how to format it, yyyy-mm-dd works.

Link to comment
https://forums.phpfreaks.com/topic/202116-strtotime-questions/#findComment-1059857
Share on other sites

Well originally it was inputted as readable format.. but I'm changing functionality so I'm inputting everything in Timestamps.

but if you are unsure how to format it, yyyy-mm-dd works.

Sure, but how would it know the difference between 01-04-2010 & 04-01-2010. Wouldn't it just choose the first format and make do with it, I'll use the YYYY-MM-DD format though. Would be nice for a bit of explaining. I don't think PHP.net mentions anything about it.

Link to comment
https://forums.phpfreaks.com/topic/202116-strtotime-questions/#findComment-1059860
Share on other sites

Well originally it was inputted as readable format.. but I'm changing functionality so I'm inputting everything in Timestamps.

but if you are unsure how to format it, yyyy-mm-dd works.

Sure, but how would it know the difference between 01-04-2010 & 04-01-2010. Wouldn't it just choose the first format and make do with it, I'll use the YYYY-MM-DD format though. Would be nice for a bit of explaining. I don't think PHP.net mentions anything about it.

 

In short, it can't parse everything, due to some formats being ambiguous.  See the link Dan provided for details.

Link to comment
https://forums.phpfreaks.com/topic/202116-strtotime-questions/#findComment-1060243
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.