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?
petewinterAsked:
Who is Participating?
 
Loganathan NatarajanLAMP DeveloperCommented:
this shows what you want,


$date = '2011/03/19';//$row_rs_tax_diary['date']


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

echo $formatted;
0
 
BardobraveCommented:
0
 
Loganathan NatarajanLAMP DeveloperCommented:
try like this,

$date = $row_rs_tax_diary['date'];

$formatted = date('M. d, Y', strtotime($date));      
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
petewinterAuthor Commented:
logudotcom - Thanks but the result was incorrect.

The result was

Nov. 03, 2019

I want it to be

Sat 19th March
0
 
Loganathan NatarajanLAMP DeveloperCommented:
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

0
 
Loganathan NatarajanLAMP DeveloperCommented:
i think you need pass the correct date format ...so that it displays well
0
 
andreizzCommented:
Use this string instead of:
$row_rs_tax_diary['date'] - this must be a timestamp

date("D jS F",$row_rs_tax_diary['date']);
0
 
Loganathan NatarajanLAMP DeveloperCommented:
you need to pass the year as "yyyy-mm-dd" ... you will get exact result
0
 
petewinterAuthor Commented:
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?
0
 
andreizzCommented:
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
0
 
andreizzCommented:
sorry i used + from javascript :P
this:


$date = "20".$row_rs_tax_diary['date'];
echo date('D jS F', strtotime($date));      
// Sat 19th March
0
 
Ray PaseurCommented:
Please read this article.  It will tell you most of what you need to know about using DATETIME fields in PHP and MySQL:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

For the requested format, Sat 19th March the date() pattern would be something like date('D jS F');
http://us2.php.net/manual/en/function.date.php

Best of luck with your project, ~Ray
0
 
petewinterAuthor Commented:
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?
0
 
andreizzCommented:
$date='11/03/19';
	$a=date("Y");
	$date=$a[0].$a[1].$date;
	echo date('D jS F', strtotime($date)); 

Open in new window


There you go :) this will work even when we will travel to other planets :D
0
 
petewinterAuthor Commented:
Many thanks all.

21st Century here we come!!! :)
0
 
petewinterAuthor Commented:
or should I say 22nd Century here we come! :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.