Finding the number of days between two dates
$now = time(); // or your date as well $your_date = strtotime(“2010-01-31”); $datediff = $now – $your_date; echo round($datediff / (60 * 60 * 24));
$now = time(); // or your date as well $your_date = strtotime(“2010-01-31”); $datediff = $now – $your_date; echo round($datediff / (60 * 60 * 24));
GROUP BY YEAR(record_date), MONTH(record_date) Check out the date and time functions in MySQL.
Use strftime: >>> from datetime import datetime >>> datetime.today().strftime(‘%Y-%m-%d’) ‘2021-01-26’ To also include a zero-padded Hour:Minute:Second at the end: >>> datetime.today().strftime(‘%Y-%m-%d %H:%M:%S’) ‘2021-01-26 16:50:03’
The WHY: dates are objects In Python, dates are objects. Therefore, when you manipulate them, you manipulate objects, not strings or timestamps. Any object in Python has TWO string representations: The regular representation that is used by print can be get using the str() function. It is most of the time the most common human … Read more
I suggest to use DateTime and DateInterval objects. $date1 = new DateTime(“2007-03-24”); $date2 = new DateTime(“2009-06-26”); $interval = $date1->diff($date2); echo “difference ” . $interval->y . ” years, ” . $interval->m.” months, “.$interval->d.” days “; // shows the total amount of days (not divided into years, months and days like above) echo “difference ” . $interval->days … Read more
This should work: date +%s
It depends on what form of date / time you want: If you want the date / time as a single numeric value, then System.currentTimeMillis() gives you that, expressed as the number of milliseconds after the UNIX epoch (as a Java long). This value is a delta from a UTC time-point, and is independent of … Read more
Use weekday(): >>> import datetime >>> datetime.datetime.today() datetime.datetime(2012, 3, 23, 23, 24, 55, 173504) >>> datetime.datetime.today().weekday() 4 From the documentation: Return the day of the week as an integer, where Monday is 0 and Sunday is 6.
isoparse function from python-dateutil The python-dateutil package has dateutil.parser.isoparse to parse not only RFC 3339 datetime strings like the one in the question, but also other ISO 8601 date and time strings that don’t comply with RFC 3339 (such as ones with no UTC offset, or ones that represent only a date). >>> import dateutil.parser … Read more
The MSDN documentation for datetime recommends using datetime2. Here is their recommendation: Use the time, date, datetime2 and datetimeoffset data types for new work. These types align with the SQL Standard. They are more portable. time, datetime2 and datetimeoffset provide more seconds precision. datetimeoffset provides time zone support for globally deployed applications. datetime2 has larger … Read more