The code I am currently using displays the date like Thursday, June 13, 2019.
Current Code: <?php echo date("l, F j, Y", strtotime(date('d-m-Y'))); ?>
How can I display the date like this instead? Thur, June 13, 2019?
Thanks
Thanks to Alex, the correct answer would be <?php echo date("D, F j, Y", strtotime(date('d-m-Y'))); ?>
<?php echo date("D, F j, Y", strtotime(date('d-m-Y'))); ?>
OutPut : Thu, June 13, 2019
More About Php Date Function: [https://www.w3schools.com/php/func_date_date.asp][1]
Related
I am saving date and time in a single column i.e 2015-04-15 13:22:58 and I want to show this time and date in this format: 15th April 2015, 1:22 pm.
I have used this code:
$dt = '2015-04-15 13:22:58';
echo date("jS F Y", strtotime($dt));
and it shows only date (15th April 2015). How can I fetch time along with date?? Any help would be highly appreciable.
Try
$dt = '2015-04-15 13:22:58';
echo date("jS F Y h:i a", strtotime($dt));
//Result is 15th April 2015 01:22 pm
echo date("jS F Y g:i a", strtotime($dt));
// Result is 15th April 2015 1:22 pm
change "jS F Y" to "js F Y g:i a". That will output the time in your desired format as well as the date.
$dt = '2015-04-15 13:22:58';
echo date("jS F Y g:i a", strtotime($dt));
Output:
15th April 2015 1:22 pm
if you want to format date time in php, you can use date_format like this.
echo date_format(strtotime($dt), "jS F Y g:i A");
I want to display my date as day/month/year.
example 31st October 2011
echo '<h4>Date Of Birth: '.$row['dob'].'</br></h4>';
You can try below code ::-
echo '<h4>Date Of Birth: '.date('dS F Y', strtotime($row['dob'])).'</br></h4>';
// ^^^^^^^ Here the is format of date, in which format you want.
Output will be ::-
31st October 2011
For more you can refer click here
<?php
$mydate = "2010-03-3";
$newDate = date("d M Y", strtotime($mydate));
$new_date = date('dS F Y', strtotime($newDate));
echo $new_date;
?>
/*Out Put*/
03rd March 2010
So if you have that data stored as or you can convert it to 3 variables representing DD MM YYYY then I'd suggest creating array of months and an array of post-fixes(don't know how to call it, but in your example it's 31st) and getting DD % 10 to use reminder for post-fix array
$month = ['January','February',....,'December']; //remember it's $month[MM-1];
$post = ['th','st','nd',...,'th'] //not sure if this on is correct but hope you get the idea
echo date('dS F Y', strtotime($row['dob']));
Refer to DateTime. I normally avoid strtotime() conversions.
Heres a working solution:
<?php
$date = '2016-11-12';
$newDate = new DateTime($date);
echo $newDate->format('jS F Y');
?>
OUTPUT:
12th November 2016
I'm having problems trying to get the time to display with php. I can get the date to work but not the time. The format it has to be in is 2:46PM on January 29 2017.
This is what I have to far.
echo date(' F j Y');
As simple as this
echo date("g:i a, F j, Y ");
According to PHP documentation http://php.net/manual/en/function.date.php
echo date('g:i A F d Y');
I would like to display this format of the current date using PHP. I have googled and found a few variances of what I want to do but the company I work for wants it specifically in this format to match what they've mailed out.
Monday, March 16, 2015
Thanks.
If you looked at the PHP documentation for date you'd be able to figure it out very easily:
echo date('l, F j, Y');
which outputs
Monday, March 16, 2015
As mentioned by #alfallouji, you should have a look at the php documentation.
Here is what you need:
$now = new \DateTime();
echo $now->format('l, F j, Y');
The date format string should be "l, F d, Y".
You can display current date in this format as below:
<?php
echo date("l, F d, Y");
?>
This is weird, i'm trying to echo out a date like Monday, January 1, 2013, but its echoing out the wrong textual day. I don't have a clue why?
I have:
<?php echo date('l, F n, Y', strtotime($do['dueDate'])); ?>
And $do['dueDate'] is the date from the database of "2013-03-22". Its formatted as DATE in mysql.
When the above echos out it says: Friday, March 3, 2013
But march 3, 2013 is a sunday...
Try like this
echo date('l ,F j ,Y', strtotime($do['dueDate']));
Try this :
n --> Numeric representation of a month, without leading zeros --> 1 through 12
j --> Day of the month without leading zeros --> 1 to 31
<?php
$do['dueDate'] = "2013-03-22";
echo date('l, F j, Y', strtotime($do['dueDate']));
?>
Output :
Friday, March 22, 2013
use this
<?php
echo date('l, F j, Y', strtotime("2013-03-22")); // output Friday, March 22, 2013
working example http://codepad.viper-7.com/rF6w1U
http://php.net/manual/en/function.date.php
n is the numerical representation of the month.
try this:
$date = "2013-03-22";
echo date('l, F j, Y', strtotime($date));
outputs:
Friday, March 22, 2013