TeddyKiller Posted May 18, 2010 Share Posted May 18, 2010 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 More sharing options...
.josh Posted May 18, 2010 Share Posted May 18, 2010 the easiest way to do it is to not let someone enter in whatever date format they want in some generic one-field-for-everything form. Create separate dropdowns for day, month and year. Link to comment https://forums.phpfreaks.com/topic/202116-strtotime-questions/#findComment-1059852 Share on other sites More sharing options...
TeddyKiller Posted May 18, 2010 Author Share Posted May 18, 2010 Yeah I do have seperate drop downs, would I use mktime with them? mktime(0,0,0,month,day,year) ? Link to comment https://forums.phpfreaks.com/topic/202116-strtotime-questions/#findComment-1059855 Share on other sites More sharing options...
.josh Posted May 18, 2010 Share Posted May 18, 2010 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 More sharing options...
TeddyKiller Posted May 18, 2010 Author Share Posted May 18, 2010 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 More sharing options...
Daniel0 Posted May 18, 2010 Share Posted May 18, 2010 http://docs.php.net/datetime.formats Link to comment https://forums.phpfreaks.com/topic/202116-strtotime-questions/#findComment-1059923 Share on other sites More sharing options...
.josh Posted May 18, 2010 Share Posted May 18, 2010 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 More sharing options...
Daniel0 Posted May 18, 2010 Share Posted May 18, 2010 In his defense, that page was added this Sunday, so it's not available on the regular mirrors yet. The regular mirrors update their copy of the manual every Friday while the docs box updates four times each day. http://svn.php.net/viewvc?view=revision&revision=299403 Link to comment https://forums.phpfreaks.com/topic/202116-strtotime-questions/#findComment-1060265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.