• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

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?
0
petewinter
Asked:
petewinter
  • 5
  • 5
  • 4
  • +2
4 Solutions
 
BardobraveCommented:
0
 
Loganathan NatarajanLAMP DeveloperCommented:
try like this,

$date = $row_rs_tax_diary['date'];

$formatted = date('M. d, Y', strtotime($date));      
0
 
petewinterAuthor Commented:
logudotcom - Thanks but the result was incorrect.

The result was

Nov. 03, 2019

I want it to be

Sat 19th March
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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
 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now