S
S
SOmar2017-02-24 14:59:01
Python
SOmar, 2017-02-24 14:59:01

Date offset 2000?

import datetime

date_time = datetime.datetime.now()
cur_date = date_time.strftime("%Y-%m-%d %H:%M:%S")
displacement_2000 = "'" + str(int(cur_date[0:4]) + 2000) + cur_date[4:len(cur_date)] + "'"
print(displacement_2000)

How to make this shit more readable.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
longclaps, 2017-02-24
@SOmar

from datetime import datetime
print(datetime.fromordinal((datetime.now().toordinal() + 730485)))
print(datetime.fromtimestamp((datetime.now().timestamp() + 730485 * 86400)))

A
aRegius, 2017-02-24
@aRegius

If you occasionally encounter this kind of task, install the python-dateutil library (it will take a couple of tens of seconds) and have fun with dates to your heart's content, simply and obviously.

>>> from datetime import datetime
>>> from dateutil.relativedelta import relativedelta
>>> now = datetime.today()
>>> print(now + relativedelta(years =+ 2000))
4017-02-24 21:11:20.779300
>>> print(now + relativedelta(months =+ 5))
2017-07-24 21:11:20.779300

A
abcd0x00, 2017-02-26
@abcd0x00

>>> import datetime
>>> 
>>> date_time = datetime.datetime.now()
>>> date_time_2000 = date_time.replace(year=date_time.year + 2000)
>>> date_time.strftime("%Y-%m-%d %H:%M:%S")
'2017-02-26 17:55:44'
>>> date_time_2000.strftime("%Y-%m-%d %H:%M:%S")
'4017-02-26 17:55:44'
>>>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question