eevan79 Posted August 17, 2010 Share Posted August 17, 2010 I store date data in MySql in this format DD-MM-YYYY , and now I need to explode this format when get information from database to get this: $day = DD , $month = MM , $year = YYYY. $result = $db->query("SELECT user_birthday FROM users WHERE user_id = " . mysql_real_escape_string($_SESSION['user_id']) . " LIMIT 1"); $row = mysql_fetch_assoc($result); $birthday = $row['user_birthday']; and I get this date format: 12-07-1980 How to explode this 3 values in day, month, year? Link to comment https://forums.phpfreaks.com/topic/210930-explode-date/ Share on other sites More sharing options...
PravinS Posted August 17, 2010 Share Posted August 17, 2010 Use combination of STR_TO_DATE(), DAY(), MONTH() and YEAR() functions in MYSQL. Link to comment https://forums.phpfreaks.com/topic/210930-explode-date/#findComment-1100192 Share on other sites More sharing options...
eevan79 Posted August 17, 2010 Author Share Posted August 17, 2010 Thanks for reply. I have tried: SELECT STR_TO_DATE(user_birthday,'%d-%m-%Y') FROM users ... and few different methods (with DAY(), MONTH() ...) but it always returns empty value. EDIT: Ok, I solve it with explode function: $parts=explode("-", $row['user_birthday']); $day = $parts[0]; $month = $parts[1]; $year = $parts[2]; Link to comment https://forums.phpfreaks.com/topic/210930-explode-date/#findComment-1100197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.