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

Add/Subtract Minutes to/from a date

34
Hello All,

I am very new to Python and Oracle, and I have a question for you all. How do you add/subtract minutes to a date? Is this possible? I need to add/subtract 30 minutes (or 60, or 90, etc) to/from a user-defined date-and-time, and then select based on that date-and-time-range. So, if I have a date looking like '2002-03-14 17:42:00', 'YYYY-MM-DD HH24:MI:SS', is there a way to add 30 minutes to it to get the right-side of the time range, etc (as in '...17:12:00' to '...18:12:00')?

Thanks in advance for any guidance!
Apr 4 '07 #1
2 19791
ghostdog74
511 Expert 256MB
Hello All,

I am very new to Python and Oracle, and I have a question for you all. How do you add/subtract minutes to a date? Is this possible? I need to add/subtract 30 minutes (or 60, or 90, etc) to/from a user-defined date-and-time, and then select based on that date-and-time-range. So, if I have a date looking like '2002-03-14 17:42:00', 'YYYY-MM-DD HH24:MI:SS', is there a way to add 30 minutes to it to get the right-side of the time range, etc (as in '...17:12:00' to '...18:12:00')?

Thanks in advance for any guidance!
you can refer to the time module. here's an example
Expand|Select|Wrap|Line Numbers
  1. >>> import time
  2. >>> c = time.strptime("2002-03-14 17:42:00","%Y-%m-%d %H:%M:%S")
  3. >>> t = time.mktime(c)
  4. >>> t
  5. 1016098920.0
  6. >>> t = t + 1800 #30 minutes is 1800 secs
  7. >>> t
  8. 1016100720.0
  9. >>> time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(t))
  10. '2002-03-14 18:12:00'
  11.  
Apr 4 '07 #2
jld730
34
Awesome!! Thank-you, thank-you, thank-you! That works!
Apr 4 '07 #3

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

Similar topics

7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
4
by: Lee | last post by:
Hi All, I have a datetime field and want to subtract 24 (or any other number of) hours from it. How would I go about this? Thanks Lee
5
by: Manny Chohan | last post by:
hI, i AM TRYING TO SUBTRACT DAYS FROM PARTICULAR DATE. i KEEP GETTING THE ERROR: hERE IS MY CODE: enddatecriteria=tempDate.AddDays(30); startdatecriteria=tempDate.AddDays(-30); I AM USING C#...
9
by: mistral | last post by:
Need help to remove list of days from date script. Need format "June 07, 2006" <SCRIPT LANGUAGE="JavaScript"> <!-- Begin // Get today's current date. var now = new Date();
5
by: Lad | last post by:
Hello, what is the best /easest way how to get number of hours and minutes from a timedelta object? Let's say we have aa=datetime.datetime(2006, 7, 29, 16, 13, 56, 609000)...
4
by: bdockery | last post by:
I'm trying to use this expression in a Query: idleTime = now() - dateRequested It just spits out gibberish numbers with 20 decimal places though. I can't find a way to specify a date format...
3
by: nihilium | last post by:
The beginning of the script goes like this. import urllib2 request = urllib2.urlopen('http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=2000') source= request.read() import re name =...
1
Stang02GT
by: Stang02GT | last post by:
Here is the issue that I am having. I have two text feilds where users need to enter a "From Date:" and a "To Date:" they then hit a update button and my code will pull back the data for the date...
1
by: Vikas Jain | last post by:
hi, please tell me how to subtract month from current date. Thanks in advance. Vikas Jain
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.