473,387 Members | 1,528 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,387 software developers and data experts.

sysdate - 5 days

1
Hi,

I new to python.

I'm trying to make changes to an existing python code .
The code has an if condition something like

if datetime(*(time.strptime(creation_date, '%d-%b-%y')[0:6])) < datetime(2006,1,1):


now instead of using datetime(2006,1,1) on the right hand side of the if condition, I wish to have a variable that is (sysdate-5days )??

thanks for any help
Jan 5 '07 #1
4 4492
bartonc
6,596 Expert 4TB
Hi,

I new to python.

I'm trying to make changes to an existing python code .
The code has an if condition something like

if datetime(*(time.strptime(creation_date, '%d-%b-%y')[0:6])) < datetime(2006,1,1):


now instead of using datetime(2006,1,1) on the right hand side of the if condition, I wish to have a variable that is (sysdate-5days )??

thanks for any help
Hello and welcome to the python forum. Here are some things to get you started:

>>> import datetime
>>> offsetTime = datetime.timedelta(-5) # negative 5 days

>>> varDate = datetime.date(datetime.MINYEAR,1,1)
>>> varDate = varDate.today()
>>> varDate
datetime.date(2007, 1, 5)
>>> varDate + offsetTime
datetime.date(2006, 12, 31)
>>>
Jan 5 '07 #2
bvdet
2,851 Expert Mod 2GB
Maybe this will help:
Expand|Select|Wrap|Line Numbers
  1. >>> datetime.datetime(1,1,1).today() - datetime.timedelta(3)
  2. datetime.datetime(2007, 1, 2, 8, 49, 30, 468000)
  3. >>> print datetime.datetime(2007, 1, 2, 8, 49, 30, 468000)
  4. 2007-01-02 08:49:30.468000
  5. >>> datetime.datetime(1,1,1).today() - datetime.timedelta(weeks=3)
  6. datetime.datetime(2006, 12, 15, 8, 51, 3, 546000)
  7. >>> print datetime.datetime(2006, 12, 15, 8, 51, 3, 546000)
  8. 2006-12-15 08:51:03.546000
  9. >>> 
Jan 5 '07 #3
bvdet
2,851 Expert Mod 2GB
More information that may be useful:
Expand|Select|Wrap|Line Numbers
  1. print '\nDifference between 2 datetime instances:'
  2. creation_date = datetime.datetime(2006,12,31,0,12,44)
  3. todays_date = datetime.datetime(1900,1,1).today()
  4. target_date = datetime.datetime(1900,1,1).today() - datetime.timedelta(5)
  5.  
  6. print 'creation_date =', creation_date
  7. print 'todays_date =', todays_date
  8. print 'target_date =', target_date
  9.  
  10. print
  11. print todays_date - creation_date
  12. print todays_date - target_date
  13.  
  14. if creation_date > target_date:
  15.     print "Greater"
  16. elif todays_date < target_date:
  17.     print "NOT Greater"
  18. else:
  19.     print "The dates are equal"
Output:
Expand|Select|Wrap|Line Numbers
  1. Difference between 2 datetime instances:
  2. creation_date = 2006-12-31 00:12:44
  3. todays_date = 2007-01-05 10:20:16.281000
  4. target_date = 2006-12-31 10:20:16.281000
  5.  
  6. 5 days, 10:07:32.281000
  7. 5 days, 0:00:00
  8. The dates are equal
Jan 5 '07 #4
bvdet
2,851 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. if creation_date > target_date:
  2.     print "Greater"
  3. elif todays_date < target_date:
  4.     print "NOT Greater"
  5. else:
  6.     print "The dates are equal"
Oops! Should be:
Expand|Select|Wrap|Line Numbers
  1. if creation_date > target_date:
  2.     print "Greater"
  3. elif creation_date < target_date:
  4.     print "NOT Greater"
  5. else:
  6.     print "The dates are equal"
Jan 5 '07 #5

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

Similar topics

1
by: WroteForLuck | last post by:
I am trying to write a simple SQL statement which will take a string (startdate) in the format DDMMYYYY and compare it to a date stored in an Oracle database. My SQL is as follows: <% "select...
1
by: Yaroslav K. Kravchishin | last post by:
Oracle 7.0.1 Server When I type SQL> select sysdate from dual; SYSDATE --------- 01-OCT-03 01-OCT-03 2 rows selected.
0
by: Yaroslav K. Kravchishin | last post by:
Oracle 7.0.1 Server When I type SQL> select sysdate from dual; SYSDATE --------- 01-OCT-03 01-OCT-03 2 rows selected.
29
by: james | last post by:
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old database file that has the date(s) stored in it as number of days. An...
5
rsrinivasan
by: rsrinivasan | last post by:
Hi, When i Execute this query, I got the result as 29-MAY-07 select sysdate from dual; But i want 29-MAY-2007. What is the query for it? Thanks,
1
by: sajithamol | last post by:
What is the difference between current_date & sysdate function?
3
by: premkumarsp1 | last post by:
hi in the oracle sysdate, time is coming wrongly. THe date and time in the OS from where i am accessing oracle and in the OS where oracle is installed is correct. I want to know how to update time...
7
by: Mike | last post by:
I have a routine that's calculating business days but its not counting the weekend days that are between the start date and end date. If my start date is 9/26/08 and my end date is 10/01/08, I...
1
by: karuppiah | last post by:
Hi All, i need query,how to select last 3 month ,last 3wek,last 3 days , this last 3 month and 3 week should be friday, using sysdate from dual table, there is no exsting table, pls any one help...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.