How do I get a value of datetime.today() in Python that is “timezone aware”?

In the standard library, there is no cross-platform way to create aware timezones without creating your own timezone class. (Edit: Python 3.9 introduces zoneinfo in the standard library which does provide this functionality.) On Windows, there’s win32timezone.utcnow(), but that’s part of pywin32. I would rather suggest to use the pytz library, which has a constantly … Read more

How do I query for all dates greater than a certain date in SQL Server?

select * from dbo.March2010 A where A.Date >= Convert(datetime, ‘2010-04-01’ ) In your query, 2010-4-01 is treated as a mathematical expression, so in essence it read select * from dbo.March2010 A where A.Date >= 2005; (2010 minus 4 minus 1 is 2005 Converting it to a proper datetime, and using single quotes will fix this … Read more

In Ruby on Rails, what’s the difference between DateTime, Timestamp, Time and Date?

The difference between different date/time formats in ActiveRecord has little to do with Rails and everything to do with whatever database you’re using. Using MySQL as an example (if for no other reason because it’s most popular), you have DATE, DATETIME, TIME and TIMESTAMP column data types; just as you have CHAR, VARCHAR, FLOAT and … Read more

What’s the difference between Instant and LocalDateTime?

tl;dr Instant and LocalDateTime are two entirely different animals: One represents a moment, the other does not. Instant represents a moment, a specific point in the timeline. LocalDateTime represents a date and a time-of-day. But lacking a time zone or offset-from-UTC, this class cannot represent a moment. It represents potential moments along a range of … Read more

How to compare two dates?

Use the datetime method and the operator < and its kin. >>> from datetime import datetime, timedelta >>> past = datetime.now() – timedelta(days=1) >>> present = datetime.now() >>> past < present True >>> datetime(3000, 1, 1) < present False >>> present – datetime(2000, 4, 4) datetime.timedelta(4242, 75703, 762105)

What is the standard way to add N seconds to datetime.time in Python?

You can use full datetime variables with timedelta, and by providing a dummy date then using time to just get the time value. For example: import datetime a = datetime.datetime(100,1,1,11,34,59) b = a + datetime.timedelta(0,3) # days, seconds, then other fields. print(a.time()) print(b.time()) results in the two values, three seconds apart: 11:34:59 11:35:02 You could … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)