gergy008 Posted February 13, 2011 Share Posted February 13, 2011 Hello everyone, I'm here again with moar problems . This time I need help converting dates, I have the jQuery UI Datepicker on my register form, Which creates a date with the format of 21/02/1995, Or "dd/mm/yyyy". Can someone explain how convert this string to "yyyymmdd"? Thanks in advance (Something tells me this will end up really simple.... Hmm......) Quote Link to comment https://forums.phpfreaks.com/topic/227495-simple-converting-dates-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 13, 2011 Share Posted February 13, 2011 The fastest way would be to explode it on the / character and then just put the pieces back together the way you want. Quote Link to comment https://forums.phpfreaks.com/topic/227495-simple-converting-dates-help/#findComment-1173441 Share on other sites More sharing options...
Pikachu2000 Posted February 13, 2011 Share Posted February 13, 2011 The datepicker should be configurable to send the date in whatever format you want, at least if it's the same one I've used in the past. Quote Link to comment https://forums.phpfreaks.com/topic/227495-simple-converting-dates-help/#findComment-1173442 Share on other sites More sharing options...
gergy008 Posted February 13, 2011 Author Share Posted February 13, 2011 The datepicker should be configurable to send the date in whatever format you want, at least if it's the same one I've used in the past. But I need it also to be user friendly, So the datepicker creates dd/mm/yyyy but php converts it to yyyymmdd I'll try it like that PFMa, I didin't think it would work but I just didn't think about it right. Quote Link to comment https://forums.phpfreaks.com/topic/227495-simple-converting-dates-help/#findComment-1173443 Share on other sites More sharing options...
gergy008 Posted February 13, 2011 Author Share Posted February 13, 2011 Got it sorted, Adding tags for google search results and heres the code. Very simple $dobs=explode("/", $dob); $newdob=$dobs[2].$dobs[1].$dobs[0]."000000"; //converts 21/02/1995 into 19950221000000 so you can directly compare with other dates in the format date("ymdhis") Quote Link to comment https://forums.phpfreaks.com/topic/227495-simple-converting-dates-help/#findComment-1173463 Share on other sites More sharing options...
Pikachu2000 Posted February 13, 2011 Share Posted February 13, 2011 The datepicker should be configurable to send the date in whatever format you want, at least if it's the same one I've used in the past. Yup, that's exactly what I meant. The jQuery datepicker I've used has the display logic completely separate from the formatting logic, as it should be. I'll try it like that PFMa, I didin't think it would work but I just didn't think about it right. Quote Link to comment https://forums.phpfreaks.com/topic/227495-simple-converting-dates-help/#findComment-1173465 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.