Jump to content

Date extracting function in SQL


vcodeinfote

Recommended Posts


$result = mysql_query("SELECT DAY(example_date), MONTH(example_date), YEAR(example_date) FROM example_table WHERE example_id = $id");

while($row = mysql_fetch_assoc($result)){
     
    $day = $row['DAY(example_date)'];
    $month = $row['MONTH(example_date)'];
    $year = $row['YEAR(eample_date)'];

}

 

Not the best example but it does contribute.

Hello,

 

Can anyone help me!!!

 

2008-07-06 16:46:15

2008-07-06 16:47:44

2008-07-06 10:18:25

2008-07-24 14:38:25

If these are the records in a table i need to get the output like this:

 

2008-07-06

2008-07-24

 

Please help

 

If you're using PHP to display the result check out substr - http://www.php.net/substr

 

echo substr($date, 0, 10);

 

will turn '2008-07-06 16:46:15' to '2008-07-06'

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.