Link to home
Start Free TrialLog in
Avatar of Pete Winter
Pete WinterFlag for United Kingdom of Great Britain and Northern Ireland

asked on

date format

I am printing dates from a database as below:

$row_rs_tax_diary['date']

Currently this prints as the following date format:

11/03/19 - i.e. Year, Month, Date

I would like it to be converted to print as

Sat 19th March

How can I do this?
Avatar of Bardobrave
Bardobrave
Flag of Spain image

Avatar of Loganathan Natarajan
try like this,

$date = $row_rs_tax_diary['date'];

$formatted = date('M. d, Y', strtotime($date));      
Avatar of Pete Winter

ASKER

logudotcom - Thanks but the result was incorrect.

The result was

Nov. 03, 2019

I want it to be

Sat 19th March
try this,
<?php
$date = '11/03/19';//$row_rs_tax_diary['date']

$formatted = date('D jS F', strtotime($date));      
// Sat 19th March

echo $formatted;

?>

Open in new window

i think you need pass the correct date format ...so that it displays well
ASKER CERTIFIED SOLUTION
Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India 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
Use this string instead of:
$row_rs_tax_diary['date'] - this must be a timestamp

date("D jS F",$row_rs_tax_diary['date']);
you need to pass the year as "yyyy-mm-dd" ... you will get exact result
logudotcom - Thanks, but the result of $row_rs_tax_diary['date'] is 11/03/19 not 2011/03/19 as you have used. This makes the result Sun 3rd November not Sat 19th March.

How can I fix this?
since this is the 21 century and will be for a long time, do something like this:

$new_date="20"+$row_rs_tax_diary['date'];

then you will have the format used by log
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
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
andreizz - Thanks I understand this the simplest solution and will not cause a problem for 89 years which I'm sure will be more than enough for my website life time, but if we were going to do this without any possible future bugs how would li be done?
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
Many thanks all.

21st Century here we come!!! :)
or should I say 22nd Century here we come! :)