How I can echo 2011-01-31 as 31 January 2011?
The input (2011-01-31) comes from the database (type: date).
Also is there any option to use locale names for the month?
Edit:
$date = date_create($row['bdate']);
echo date_format($date, 'd F Y'); //31 January 2010
could be solution but date_format has no option for other languages(?). Is there any solution? Like 31 Ocak 2011
Probably is strftime what you seek.
Example:
echo strftime('%d %B %Y', strtotime($db_entry));
Use strtotime to convert 2011-01-31 to a timestamp:
echo date( 'd F Y', strtotime( $row['bdate'] ) );
<?php
echo date('d F Y', strtotime("2011-01-31"));
Demo: http://codepad.org/WPe1xCFz
Try using strftime()
$date = strtotime($row['bdate']);
echo strftime('%d %B %Y', $date);
Related
I am trying to convert a date to month name and year.
$date = '2017-07-00';
$date = date('m/y', strtotime($date));
echo DATE_FORMAT($date, '%M %Y');
I am expecting output like
July, 2017
Here is error i am getting
Warning: date_format() expects parameter 1 to be DateTimeInterface, string given
No Need of DATE_FORMAT() function.
Example-1: If 00 used in day. Then, output will be June, 2017
<?php
$date = '2017-07-00';
echo date('F, Y', strtotime($date)); //June, 2017
?>
Example-2: If 01 or valid day used in day. Then, output will be July, 2017
<?php
$date = '2017-07-01';
echo date('F, Y', strtotime($date)); //July, 2017
?>
You are not using correct parameters, use F for moth and Y for year
Full code:
$date = '2017-07-00';
$date = date('F, Y ', strtotime($date));
echo $date;
Try This.
$date = '2017-07-01';
$date = date('F, Y', strtotime($date));
echo $date;
You can use this
echo date('F,Y',strtotime($date));
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
Ok, there's tons of questions about this and i try most of the solutions i found there without success.
I have a form passing a date in this format to the PHP function: 26/11/2014
In the function i have to transform it in other forms and this is my code:
$date_1 = date('d F Y', strtotime($_REQUEST['date']));
setlocale (LC_TIME, 'de_DE');
$date_transl = strftime('%d %B %Y', strtotime($_REQUEST['date']));
In both case i'm having returned 01 January 1970 so i'm facing 2 problems:
1) date returned is wrong
2) strftime is not translating the date
Replace the / characters with - and it will do the job:
$_REQUEST['date'] = str_replace('/','-',$_REQUEST['date']);
$date_1 = date('d F Y', strtotime($_REQUEST['date']));
setlocale (LC_TIME, 'de_DE');
$date_transl = strftime('%d %B %Y', strtotime($_REQUEST['date']));
Try
$date_1 = date('d F Y', strtotime(str_replace('/','-','26/11/2014')));
I have my users entering the date in this format :- mm/dd/yyyy (11/21/2012)
My PHP script converts the date into the following format :- dd-Month-yyyy (21-November-2012)
I do this using :-
$new_date = date('d-F-Y', strtotime($user_date));
How can I have the date in this format :- 21st November 2012?
Thanks
You can use S letter as following:
$new_date = date('jS F Y', strtotime($user_date));
Check manual.
It will output as you expect
$my_date = '2016-01-01';
echo date('F jS, Y', strtotime($my_date));
# January 1st, 2016
while dS will also prepends 0
echo date('F dS, Y', strtotime($my_date));
# January 01st, 2016
$new_date = date('jS F Y', strtotime($date));
S - English ordinal suffix for the day of the month, 2 characters
(st, nd, rd or th. Works well with j)
**My Date = 22-12-1992**
<?php
$mydate = "22-12-1992";
$newDate = date("d M Y", strtotime($mydate));
$new_date = date('dS F Y', strtotime($newDate));
echo $new_date;
?>
**OutPut = 22nd December 1992**
You can use something like:
echo date('l, F jS');
Or even get a bit fancy with the HTML:
echo date('l, F j<\s\u\p>S</\s\u\p>');
You can do that :
<?php echo date('dS M. Y');?>
$date = date_create('09-22-2012');
echo $date->format('d S F Y');
by this code you will get your desire
for more you can also visit http://php.net/manual/en/datetime.formats.date.php
I have the following string:
$date = 2011-08-29 14:53:15;
when I do this:
echo date('F j, Y', $date);
I get December 31, 1969 instead of August 29, 2011. How to get the right date?
Use strtotime on your $date value.
echo date('f j, Y',strtotime($date));
<?php
$date = strtotime($date);
echo date('F j, Y', $date);
?>
To explain...
The function date() is expecting a unix time-stamp (something like 23498034). the function strtotime() takes a normal looking date that a person would make, and converts it to a timestamp. Then you're good to go.