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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hours time

Status
Not open for further replies.

jayjay555

Programmer
May 4, 2009
13
CA
Hi,

I have a "text field c(5)" with examples as such:

01:45
09:34
11:46
13:08
14:33
17:01
22:49
etc.

which is a time field (i.e: the timestanp). I need to find 3 hours + that field. N.B,

any simple way?

please help.


Thanks,
JJ
 
Personally, I wouldn't store time data in a character field; I'd use datetime.

However, given that's what you have, you should be able to do something like (untested):

Code:
cHour = LEFT(cTime, 2)
nHour = VAL(m.cHour)

nNewHour = m.nHour + 3
IF m.nNewHour > 23
   nNewHour = m.nNewHour - 24
ENDIF 

cNewTime = TRANSFORM(m.nNewHour) + SUBSTR(cTime, 3)

If you need a more general approach, where the number of hours you're adding could vary, then change the IF to use MOD() so that even if you add more than a day's worth, it'll work:

Code:
nNewHour = m.nHour + m.nHoursToAdd
nNewHour = MOD(m.nNewHour, 24)

I think this approach will work better if it turns out you're subtracting rather than adding, too.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top