How to add hours and minutes?

forum.sourcecode (2000-2005) & forum.td.sourcecode (2005-2010)
Paul Schmitteck

How to add hours and minutes?

Post by Paul Schmitteck » 05 Jan 2006, 14:40

 Posted by:  Paul Schmitteck 

Hi friends,
I have one date Datafield (DAY), which is formatted as hh:mm (say for
example it may populate 7:30).
After this i need to multiply with 5 for a week and i need to populate
37:30 in another Datafield WEEK and multiply with 29 to populate MONTH and
365 to populate year datafield?
Can any one suggest some idea here please!
Thanks and Regards,
Vijay.K

Catalin Enache

Re: How to add hours and minutes?

Post by Catalin Enache » 05 Jan 2006, 15:39

 Posted by:  Catalin Enache 

Use SalDateHour and SalDateMinute.

Something like
Set nMinutes = (SalDateHour(DAY)*60 + SaldateMinute (DAY) )*5
Set nWeekHours = nMinutes /60 - SalNumberMod (nMinutes , 60)/60
Set nWeekMinutes = nMinutes - nWeekHours*60

So WEEk datafield will be equal with somethink like nWeekHours:nWeekMinutes.

Catalin

Alois Fuchs

Re: How to add hours and minutes?

Post by Alois Fuchs » 23 Feb 2006, 19:34

 Posted by:  Alois Fuchs 

hi paul,

you can simply add (or also subtract) days/hours/minutes/seconds, calculated
as a (fractional) part of a 24 hour's day, to a date - like this:

Date/Time: dDate1
Date/Time: dDate2
Number: nDateDiff

! set dDate1 to a certain value:
Set dDate1 = 2006-02-23
! to add, for example, 1 d 12 h 25 m 32 s, convert all to seconds:
Set nDateDiff = ( 1*24*60*60 + 12*60*60 + 25*60 + 32 ) / ( 24*60*60 )
Set dDate2 = dDate1 + nDateDiff ! it works properly, no error
"assignment of different types" occurs!
Call SalMessageBox( SalFmtFormatDateTime( dDate2, 'yyyy-MM-dd hhhh:mm:ss' ),
'new date/time', MB_Ok )
! dDate2 shows 2006-02-24 12:25:32
! add another 45 m 10 s:
Set nDateDiff = ( 45*60 + 10 ) / ( 24*60*60 )
Set dDate2 = dDate2 + nDateDiff
Call SalMessageBox( SalFmtFormatDateTime( dDate2, 'yyyy-MM-dd hhhh:mm:ss ),
'new date/time', MB_Ok )
! dDate2 shows 2006-02-24 13:10:42

alois

Return to “td.sourcecode”

Who is online

Users browsing this forum: [Ccbot] and 0 guests