alecks Posted January 9, 2008 Share Posted January 9, 2008 just a quick question: the function strtotime converts strings formatted like dates into unix timestamps. This is great, but how do I tell it to only expect one format? for example: the date 1-08-2008 could be interpreted as January 8th, 2008, or August 1st, 2008. I want it mm-dd-yyyy. thanks Quote Link to comment https://forums.phpfreaks.com/topic/85247-strtotime-different-dates/ Share on other sites More sharing options...
Ken2k7 Posted January 9, 2008 Share Posted January 9, 2008 just a quick question: the function strtotime converts strings formatted like dates into unix timestamps. This is great, but how do I tell it to only expect one format? for example: the date 1-08-2008 could be interpreted as January 8th, 2008, or August 1st, 2008. I want it mm-dd-yyyy. thanks If you mean to check if the user has entered in a certain format, you have to use preg_match(), ereg, or eregi and use RegExp. Quote Link to comment https://forums.phpfreaks.com/topic/85247-strtotime-different-dates/#findComment-434877 Share on other sites More sharing options...
alecks Posted January 9, 2008 Author Share Posted January 9, 2008 I don't mean that at all, because that wouldn't help :/ I want strtotime to assume that any date strings given to it are in a certain format, for example m-d-yyyy. I want this because sometimes when a date is given to it it will think that it is in a different format, d-m-yyyy for example. For example, if I gave it the m-d-yyyy date 1-8-2008, it will give me back a timestamp for 8-1-2008, which is not what I want. Quote Link to comment https://forums.phpfreaks.com/topic/85247-strtotime-different-dates/#findComment-434893 Share on other sites More sharing options...
kenrbnsn Posted January 9, 2008 Share Posted January 9, 2008 if you change the dashes to slashes, then your format will work as you want: <?php echo date('Y-m-d',strtotime(str_replace('-','/','1-8-2008'))); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/85247-strtotime-different-dates/#findComment-434916 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.