473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Date Time in Python

Suppose i have a present date and i want to check the date after 90 days than by which method i can do that
Apr 5 '07 #1
3 1678
ghostdog74
511 Expert 256MB
Suppose i have a present date and i want to check the date after 90 days than by which method i can do that
you can use the datetime module
Expand|Select|Wrap|Line Numbers
  1. >>> import datetime
  2. >>> nowdate = datetime.date(2007, 1, 1)
  3. >>> ninety_days = datetime.timedelta(days=90)
  4. >>> after_90 = nowdate + ninety_days
  5. >>> after_90
  6. datetime.date(2007, 4, 1)
  7. >>> after_90.ctime()
  8. 'Sun Apr  1 00:00:00 2007'
  9.  
Apr 5 '07 #2
Expand|Select|Wrap|Line Numbers
  1. import time
  2.  
  3. def parseDate(date):
  4.   t = time
  5.   structT = t.strptime(date,'%Y/%m/%d')
  6.   objT = t.mktime(structT)
  7.   return objT
  8.  
  9.  
  10. if __name__ == '__main__':
  11.         t = time
  12.         t1 = parseDate('2007/04/06')
  13.  
  14.         t2 = t1 + 90*24*60*60
  15.         x = t.localtime(t2)
  16.         print str(t.strftime('%Y/%m/%d',x))
  17.  
  18.  
In the above program parseDate() takes date in a specific format and returns the date after 90 days in the same format..
You can customize it according to ur needs

hope this was helpful
Apr 6 '07 #3
ghostdog74
511 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. import time
  2.  
  3. def parseDate(date):
  4.   t = time...
  5. ....
  6.  
the above is shortened like this
Expand|Select|Wrap|Line Numbers
  1. import time as t
  2.  
Apr 6 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
6
by: Kory Wheatley | last post by:
In Python how would you print the date in a file, I have a logging program written in python and for each new recorded added to the file, I would like to print the date, something like this...
9
by: tertius | last post by:
Hi, Is there a more pythonic way to write or do a date difference calculation? I have as input two date fields in the form 'YYYY-MM-DD' TIA Terius
2
by: praba kar | last post by:
Dear All, In Php strtotime() will change a date string into timestamp. I want to know which python function will change a date string into timestamp. Date string format is below
1
by: praba kar | last post by:
Dear All, In Php we can print RFC 2822 formatted date by date('r') with parameter r. Then it will print the below format date. "Thu, 7 Apr 2005 01:46:36 -0300". I want to print same RFC 2822...
1
by: nephish | last post by:
Hey there, i am doing a plotting application. i am using mxRelativeDateTimeDiff to get how much time is between date x and date y now what i need to do is divide that time by 20 to get 20 even...
2
by: Joshua J. Kugler | last post by:
I've read docs (datetime, time, pytz, mx.DateTime), googled, and experimented. I still don't know how to accomplish what I want to accomplish. I'm loading up a bunch of date/time data that I...
3
by: nano | last post by:
Using python 2.2 what is the simplest way to get the current date value? I have looked in so many places. The question is often asked and the usual response indicates how to get the current date...
6
by: krishnakant Mane | last post by:
hello, I am strangely confused with a date calculation problem. the point is that I want to calculate difference in two dates in days. there are two aspects to this problem. firstly, I can't get...
6
by: Jeremy Sanders | last post by:
Hi - I need to add support to a program for dates and times. The built-in Python library seems to be okay for many purposes, but what I would like would be Unix epoch style times (seconds relative...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.