Tommi Quack
Tommi Quack

Reputation: 45

Python add days to date without datetime library

Is there a way to achieve this without using the datetime library since I need to implement it on a python template in Deployment Manager and it does not support this library (only "time" library)?

date = current_date
Input: 30
Output: current_date + 30

Upvotes: 0

Views: 337

Answers (1)

BoarGules
BoarGules

Reputation: 16952

The time module will give you the current date using time.time().

This is in seconds. To add 30 days, you add 30 days' worth of seconds.

>>> import time
>>> current_date = time.time()
>>> time.ctime(current_date)
'Mon Mar 04 11:45:20 2019'
>>> plus30days = current_date + 30 * 24 * 60 * 60
>>> time.ctime(plus30days)
'Wed Apr 03 12:45:20 2019'

There is an hour difference because in my timezone the clocks go forward in the next 30 days.

Upvotes: 1

Related Questions