Jump to content

Explode date


eevan79

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.