0

I am using the .st_birthtime method to get the date of creation of a file.

The result looks like:

1359492652

which I can convert to a more readable format

2013-01-29 21:50:52

using

datetime.datetime.fromtimestamp(statinfo.st_birthtime)

My question is: how can I convert it to YYYYMMDD format? I don't give importance of the hours and minutes. In this example the result should be

20130129

Something like the SELECT CONVERT(VARCHAR(10), @date, 112) of T-SQL. I am using Python version 3.5.3 and MacOS.

Community
  • 1
  • 1
Nicolaesse
  • 2,554
  • 12
  • 46
  • 71

1 Answers1

0

It's this what you wanted?

#time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(1359492652))
time.strftime('%Y%m%d', time.gmtime(1359492652))

I've assumed that 1359492652 is the total of seconds so this is the right date formatters for Python, tested it in Python 3 interpreter. The first line which is a comment is the same result as you had with the datetime method.

if you want here is a link for the strftime behaviour: https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior

Gustavo Gomes
  • 317
  • 5
  • 13