Jump to content

[SOLVED] mysql date transforming


xiao

Recommended Posts

<?php
$date = explode("-", $info['submitdatum']);
$day=$date[2];
$month=$date[1];
$month = substr($month,0,3);
?>

 

RESULTS

 

Oct

 

Also an easier way to do this is by transforming it when you put it in the DB. For example

 

 

<?php
$current = time();
$current = date("Y-m-d",$current);
// Do query
$month = explode("-",$current);
$month = $month[1];
 
echo $month; // JAN, SEP, ...etc
?>

 

http://ca3.php.net/substr

http://ca3.php.net/manual/en/function.date.php

Just do it directly in your mysql SELECT query -

 

SELECT DATE_FORMAT(submitdatum,'%e %b') FROM your_table WHERE your_where_conditions...

 

This returns the day of the month, numeric (0..31) and the abbreviated month name (Jan..Dec)

 

Done!

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.