Changing from any input format to required date format
Object oriented style
$date = DateTime::createFromFormat('d.n.Y', '06.1.2017');
echo $date->format('Y-M-d'); // Output is 2017-Jan-06
Procedural style
$date = date_create_from_format('Y/F/j', '2017/April/6');
echo date_format($date, 'Y-m-d'); // Output is 2017-04-06
Using Time formats
$date = DateTime::createFromFormat('d/m/Y H:i:s', '06/12/2017 23:34:59');
echo $date->format('h:i:s A'); // Output is 11:34:59 PM
Here is a list of Chars which can be used for creating different date formats.
Datedday of the month, 2 digits with leading zeros; i.e. '01' to '31'
jday of the month without leading zeros; i.e. '1' to '31'
DayDday of the week, textual, 3 letters; i.e. 'Fri'
lday of the week, textual, long; i.e. 'Saturday'
wday of the week, numeric, i.e. '0' (Sunday) to '6' (Saturday)
zday of the year; i.e. '0' to '365'
tnumber of days in the given month; i.e. '28' to '31'
rRFC 822 formatted date; i.e. 'Thu, 21 Dec 2000 16:01:07 +0200' (added in PHP 4.0.4)
Monthmmonth; With leading zeros; i.e. '01' to '12'
nmonth without leading zeros; i.e. '1' to '12'
Mmonth, textual, 3 letters; i.e. 'Jan'
Fmonth, textual, long; i.e. 'January'
YearYyear, 4 digits; i.e. '2018'
yyear, 2 digits; i.e. '19'
Hourghour, 12-hour format without leading zeros; i.e. '1' to '12'
Ghour, 24-hour format without leading zeros; i.e. '0' to '23'
hhour, 12-hour format; i.e. '01' to '12'
Hhour, 24-hour format; i.e. '00' to '23'
Minutesiminutes; i.e. '00' to '59'
iminutes; without leading zero; intval(date('i'));
Secondssseconds; i.e. '00' to '59'
sseconds; without leading zero; intval(date('s'));
a'am' or 'pm'
A'AM' or 'PM'
BSwatch Internet time
I'1' if Daylight Savings Time, '0' otherwise.
Lboolean for whether it is a leap year; i.e. '0' or '1'
TTimezone setting of this machine; i.e. 'MDT'
Useconds since the epoch
Ztimezone offset in seconds (i.e. '-43200' to '43200'). The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Your Rating


More On Date Object

Post Comment This is for short comments only. Use the forum for more discussions.

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2017 All rights reserved worldwide Privacy Policy Disclaimer