How to convert AM/PM timestmap into 24hs format in Python?

This approach uses strptime and strftime with format directives as per https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior, %H is the 24 hour clock, %I is the 12 hour clock and when using the 12 hour clock, %p qualifies if it is AM or PM. >>> from datetime import datetime >>> m2 = ‘1:35 PM’ >>> in_time = datetime.strptime(m2, “%I:%M %p”) … Read more

check if date time string contains time

The date time components TimeOfDay is what you need. MSDN says “Unlike the Date property, which returns a DateTime value that represents a date without its time component, the TimeOfDay property returns a TimeSpan value that represents a DateTime value’s time component.” Here is an example with consideration of all your scenarios. Since you are … Read more

Python module to change system date and time

import sys import datetime time_tuple = ( 2012, # Year 9, # Month 6, # Day 0, # Hour 38, # Minute 0, # Second 0, # Millisecond ) def _win_set_time(time_tuple): import pywin32 # http://timgolden.me.uk/pywin32-docs/win32api__SetSystemTime_meth.html # pywin32.SetSystemTime(year, month , dayOfWeek , day , hour , minute , second , millseconds ) dayOfWeek = datetime.datetime(time_tuple).isocalendar()[2] pywin32.SetSystemTime( … Read more

python time offset

Use a datetime.datetime(), then add or subtract datetime.timedelta() instances. >>> import datetime >>> t = datetime.datetime.now() >>> t – datetime.timedelta(hours=1, minutes=10) datetime.datetime(2012, 12, 26, 17, 18, 52, 167840) timedelta() arithmetic is not supported for datetime.time() objects; if you need to use offsets from an existing datetime.time() object, just use datetime.datetime.combine() to form a datetime.datetime() instance, … Read more

Converting ISO 8601 date time to seconds in Python

If you want to get the seconds since epoch, you can use python-dateutil to convert it to a datetime object and then convert it so seconds using the strftime method. Like so: >>> import dateutil.parser as dp >>> t=”1984-06-02T19:05:00.000Z” >>> parsed_t = dp.parse(t) >>> t_in_seconds = parsed_t.timestamp() >>> t_in_seconds ‘455051100’ So you were halfway there … Read more

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