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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.