473,422 Members | 1,768 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,422 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 19798
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: 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: 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
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.