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? Quote Link to comment 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. Quote Link to comment 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]; Quote Link to comment 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.