# From a date Object:
date_format ( DateTimeInterface $object , string $format )
# From the current time
$dateTime = new DateTime();
// or pass a string or int ->`DateTime($date_time)`
$dateTime->format('y-j-d H:i:s T'); #print ex: 21-2-02 16:00:01 PST
# Or a quick one-liner:
date('g:i A m-d-Y', strtotime($date_time)); #print ex: 2:00 PM 02-02-2021
<?php
$deliverytime = new DateTime('2014-09-08 06:00:00');
$hour = $deliverytime->format('H');
if ($hour < 12) {
echo "Morning";
} else {
echo "Afternoon or evening";
}
?>
DateTime date = DateTime.Now.AddHours(26);
DateTime dateNow19 = new DateTime(date.Year, date.Month, date.Day, 19, 00, 00);
DateTime dateNow08 = new DateTime(date.Year, date.Month, date.Day, 08, 00, 00);
Console.WriteLine(date);
Console.WriteLine(dateNow19);
Console.WriteLine(dateNow08);
if (date < dateNow19 && date > dateNow08)
{
Console.WriteLine("Success19");
}
else
{
Console.WriteLine("False");
}
//first day and last day of month
DateTime date = ...
var firstDayOfMonth = new DateTime(date.Year, date.Month, 1);
var lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1);
dateutil - powerful extensions to datetime
pip install python-dateutils