Click to See Complete Forum and Search --> : Getting, Setting and Comparing time?


Shahzad
April 6th, 1999, 08:57 PM
1.
I want to take a time from a user when he types in an edit box in digital format
(hr : min : sec ) How can I set a time object equal to this time at run time.

2.
Furthermore I have to compare between two times but the CTimeGetCurrentTime() function returns a time consisting of date stuff also so it hurdles in comparison of time and changes the criteria some what. I don't want to compare the date part but juss the time part in hours, minuts and seconds.

jteagle@home
April 11th, 1999, 08:23 AM
As you only want to deal with times, use GetCurrentTime to get the current date and time. Get the date, month and year parts from this CTime, and then create a new CTime with these collected parts plus the time parts from the user. You then have a CTime object with today's date and the user's time. When retrieving the time, simply call the relevant Get...() methods and ignore the date.

Because you now have a CTime object with today's date and the user's time, you CAN safely use GetCurrentTime() for a time comparison because the dates will be the same (the only danger is if the comparison occurs after midnight whereas the user's time was collected before midnight - in which case the dates will be different, but slim chance - you can always use the relevant Get...() methods to extract the time components and do a manual comparison).

Does this help?


_ _
o o Jason Teagle
<
v jteagle@geocities.com

Shahzad
April 11th, 1999, 12:14 PM
What you wrote is quit logical but I have switched to COleDateTime to deal with my problem. It has a function SetTime(hr,min,sec), so the task is quite easy now. Moreover you can attach COleDateTime object to an edit box using class wizard and then your edit box will accept data only either in date or time or data&time format. You know the rest is easy!
Thankx your your help anyway.