Get month from string date php
Given the following timestring: Show
How to get the year/month/day in PHP?
I don't know why I get 1969 for year. Thank you asked Aug 31, 2010 at 3:51
You can use
Note that
RRikesh 13.6k5 gold badges47 silver badges68 bronze badges answered Aug 31, 2010 at 3:53
0 PHP - How to get year, month, day from time string
user1438038 5,6776 gold badges57 silver badges85 bronze badges answered Nov 6, 2015 at 10:13
1 Update: Forgot to add semicolon at end of first line, try this:
Hopefully that will get you going!
Mike Purcell 19.5k10 gold badges51 silver badges86 bronze badges answered Aug 31, 2010 at 3:54
Raphael CaixetaRaphael Caixeta 7,7749 gold badges50 silver badges76 bronze badges Using the object-oriented programming style, you can do this with DateTime class
Then, you can decompose your date using the format() method
If you prefer the numeric format, instead of the string format, you can use the intval() function
Here some formats that you can use
Here the entire list of the formats that you can use : http://php.net/manual/en/function.date.php answered Feb 1, 2015 at 12:14
TyphonTyphon 8061 gold badge12 silver badges19 bronze badges PHP - we can get year, month, day from time string in many formats.
answered Jan 15, 2021 at 3:27
1 How to get month from specific date in php?$dateObj = DateTime::createFromFormat( 'jS F Y' , '5th February 1993' ); echo "The 2 digit representation of current month with leading zero is: " . $dateObj ->format( 'm' );
How get month Name in php?php $date = "2019-11-11"; echo "Displaying date... \n"; echo "Date = $date"; $month_name = date("F", mktime(0, 0, 0, 11, 10)); echo "\nMonth = ".
How to display months in php?To show the previous month we would have to introduce the mktime() function and make use of the optional timestamp parameter for the date() function. Like this: echo date('F Y', mktime(0, 0, 0, date('m')-1, 1, date('Y'))); This will also work (it's typically used to get the last day of the previous month):
How to date format in php?Change YYYY-MM-DD to DD-MM-YYYY
In the below example, we have date 2019-09-15 in YYYY-MM-DD format, and we will convert this to 15-09-2019 in DD-MM-YYYY format. $orgDate = "2019-09-15"; $newDate = date("d-m-Y", strtotime($orgDate));
|