Link to home
Start Free TrialLog in
Avatar of dimensionav
dimensionavFlag for Mexico

asked on

How to show a formatted date?

I have a value from a field datetime in a mysql database and I want to show it formatted as a mm-dd-yyyy using php, how could be possible?
ASKER CERTIFIED SOLUTION
Avatar of johanntagle
johanntagle
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dimensionav

ASKER

If the date appears in english like this 01-jan-2012 and I want it in a different language what could I do?
If you want to display date in different languages, you need to create your own function for that.

Eg:

function getMonthText($month, $lang) {
     global $config;
     return $config['$lang']['month'][$month'];
}

Open in new window


and you have your $config prepared like this (in some config file)

//month text for english
$config['en']['month'][1] = 'January';
$config['en']['month'][2] = 'February';
$config['en']['month'][3] = 'March';
...

Open in new window


and then the formatted date (where $timestamp is result of strtotime() with your date from DB)

$date = getMonthText(date('j', $timestamp), 'en') .'-'. date ('d-Y', $timestamp);

Open in new window