sintax63 Posted June 22, 2011 Share Posted June 22, 2011 I have two fields in my table called start_date and end_date. The date format for each is xx/xx/xx. I know how to do something like: if ($start_date_month == "8") { $start_month = "August"; } So I can change the 1 or 2 digit months to names. What I'm not sure how to do is strip out both the month and day from the full xx/xx/xx format. Any help would be much appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/240140-converting-date-format-081211-to-august-12/ Share on other sites More sharing options...
Pikachu2000 Posted June 22, 2011 Share Posted June 22, 2011 If you had stored the values in the proper DATE or DATETIME type field, this would be very easy. I hope it isn't too late to change them to the right format. Quote Link to comment https://forums.phpfreaks.com/topic/240140-converting-date-format-081211-to-august-12/#findComment-1233479 Share on other sites More sharing options...
Maq Posted June 22, 2011 Share Posted June 22, 2011 If not ^, something like this: echo date("F d", strtotime("08/12/11")); Check out the manual - date. Quote Link to comment https://forums.phpfreaks.com/topic/240140-converting-date-format-081211-to-august-12/#findComment-1233480 Share on other sites More sharing options...
TeNDoLLA Posted June 22, 2011 Share Posted June 22, 2011 Or using php's DateTime class. $date = '08/12/11'; $date = DateTime::createFromFormat('m/d/y', $date); echo $date->format('F d'); Quote Link to comment https://forums.phpfreaks.com/topic/240140-converting-date-format-081211-to-august-12/#findComment-1233481 Share on other sites More sharing options...
sintax63 Posted June 22, 2011 Author Share Posted June 22, 2011 If you had stored the values in the proper DATE or DATETIME type field, this would be very easy. I hope it isn't too late to change them to the right format. I wish it was possible. This is how I store dates / date time in my personal coding but I'm getting these values from a CSV file that I'm importing into phpMyAdmin. Quote Link to comment https://forums.phpfreaks.com/topic/240140-converting-date-format-081211-to-august-12/#findComment-1233482 Share on other sites More sharing options...
sintax63 Posted June 22, 2011 Author Share Posted June 22, 2011 If not ^, something like this: echo date("F d", strtotime("08/12/11")); Check out the manual - date. This did the trick! Thank you so much for the insanely quick help. Quote Link to comment https://forums.phpfreaks.com/topic/240140-converting-date-format-081211-to-august-12/#findComment-1233490 Share on other sites More sharing options...
Psycho Posted June 22, 2011 Share Posted June 22, 2011 If you had stored the values in the proper DATE or DATETIME type field, this would be very easy. I hope it isn't too late to change them to the right format. I wish it was possible. This is how I store dates / date time in my personal coding but I'm getting these values from a CSV file that I'm importing into phpMyAdmin. So, convert the values to proper dates when putting them in the database instead of storing them as strings. Perhaps you are too young to remember the significance of Y2K Quote Link to comment https://forums.phpfreaks.com/topic/240140-converting-date-format-081211-to-august-12/#findComment-1233492 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.