aeroswat Posted February 23, 2010 Share Posted February 23, 2010 I have date strings formatted as mm/dd/yyyy and need them formatted for MySQL before I insert them so I'm using this: date_format(date_create($date),'Y-m-d'); Quote Link to comment https://forums.phpfreaks.com/topic/193126-is-there-a-better-way-of-doing-this/ Share on other sites More sharing options...
ialsoagree Posted February 23, 2010 Share Posted February 23, 2010 I'm not sure if it's possible for you to make this change, but I found that just saving timestamps was a smoother way of doing things for me. PHP makes it very easy to use unix timestamps (and the unix timestamp stores the time zone), I never wind up doing any date related work in MySQL (except sorting, which you can do just as easily with timestamps). Of course, that's obviously not a solution in all cases. Quote Link to comment https://forums.phpfreaks.com/topic/193126-is-there-a-better-way-of-doing-this/#findComment-1017025 Share on other sites More sharing options...
aeroswat Posted February 23, 2010 Author Share Posted February 23, 2010 I'm not sure if it's possible for you to make this change, but I found that just saving timestamps was a smoother way of doing things for me. PHP makes it very easy to use unix timestamps (and the unix timestamp stores the time zone), I never wind up doing any date related work in MySQL (except sorting, which you can do just as easily with timestamps). Of course, that's obviously not a solution in all cases. Would be a good idea but i don't think that I really gotta make that big of a change. I just wanted to see if there might be a better way to accomplish this. I have one of those pop-up calendar's where they select their date and it populates a read-only text box. So the user can't screw it up Quote Link to comment https://forums.phpfreaks.com/topic/193126-is-there-a-better-way-of-doing-this/#findComment-1017031 Share on other sites More sharing options...
ignace Posted February 24, 2010 Share Posted February 24, 2010 make your database field datetime and use: $sqlDate = date('Y-m-d', strtotime($date)); Quote Link to comment https://forums.phpfreaks.com/topic/193126-is-there-a-better-way-of-doing-this/#findComment-1017671 Share on other sites More sharing options...
jl5501 Posted February 24, 2010 Share Posted February 24, 2010 If you are using a datepicker for these dates then there is probably a config setting for the date format to use Quote Link to comment https://forums.phpfreaks.com/topic/193126-is-there-a-better-way-of-doing-this/#findComment-1017675 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.