Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding minutes to a Time or Timestamp

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have tried several attempts to add some number of minutes to a Timestamp and also tried with Time.

For example,
update t1 set timecol = Time(Timestamp(datecol, timecol) + '00:15:00')

TIA.

 
if i well remember there's an integrete function name minute you select and cast to minute and add at the same time the number of minute you wish. I'm not sure all my notes are left at my office have a look if there's a prob
answer me for more explain i'll do my best but not befor wednesday
 
Take a look at the following selection where I added 1440 minutes(1 day) to a timestamp. You should be able to adapt this quite easily for your update statement.


db2 => select current timestamp from sysibm.sysdummy1

1
--------------------------
2002-04-23-12.04.52.363938

1 record(s) selected.


Add 1440 minutes on to the timestamp

db2 => select current timestamp + 1440 minutes from sysibm.sysdummy1

1
--------------------------
2002-04-24-12.05.13.308158

1 record(s) selected.

Hope this is of use to you.

Greg

 
To add any 'time' to a timestamp:

SELECT CURRENT TIMESTAMP + 1 SECOND
SELECT CURRENT TIMESTAMP + 1 MINUTE
SELECT CURRENT TIMESTAMP + 1 HOUR
SELECT CURRENT TIMESTAMP + 1 DAY
SELECT CURRENT TIMESTAMP + 1 MONTH
SELECT CURRENT TIMESTAMP + 1 YEAR

Same works for subtraction.

Hope this helps

Marc Lodge
 
Awesome! Exactly what I needed. Can anyone give a newby any tips on how to learn this stuff?

Thanks!
 
Cisco,
SQL as a rule is pretty plain and boring. It can be complicated with JOINs and everything, but once you've learnt it, you don't tend to forget it. The 'functions' on the other hand are a little bit more interesting, and, as you don't tend to use them that often, you forget the format. If you have a bit of time to spare, mess around with the date/time functions eg. write a bit of sql that gives the day number from 1 to 7 from a given date. Or make it a bit hard by trying to get the day name in there instead. Or count the number of rows in a table for a particular year/product/employee where there are more than 10 occurences. Doing this sort of thing with the 'functions' will help you to understand what they are doing, and how you can use them. It should give you a feel for what you can achieve in SQL. Have fun and if you get stuck, post it here; There's a lot of people in this forum who will help out.
Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top