mierlp Posted September 19, 2020 Share Posted September 19, 2020 Hi What's the best way to work with time controls. My table now has 2 fields of type time, namely: - startTime - endTime The user must enter a period with a start-time and end-time. For example : Evening 6:00 pm - 10:00 pm Night 10:00 pm - 2:00 am I would like to check if the startTime is not greater than the endTime because then it is not correct. This works well as long as the endTime is less than 00:00. In the situation such as 22:00-02:00 that does NOT work because startTime is greater than endTime but it is a valid period. We do NOT use a date because they are block times for a period. What's the best way to solve this including a controle Quote Link to comment Share on other sites More sharing options...
x11 Posted September 19, 2020 Share Posted September 19, 2020 convert to float and compare Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted September 20, 2020 Share Posted September 20, 2020 Hello Peter, Why don't use TDateTime ? 22/09/2020 : 02:00:00 - 21/09/2020 : 22:00:00 should give the correct result. Quote Link to comment Share on other sites More sharing options...
Ron Posted September 22, 2020 Share Posted September 22, 2020 If all you have are the hours, 02 will always be less than 22 - so you need more data than just the hours. When crossing into a new day, you need to differentiate between dates, so you need some date reference for each point in time. Whatever the reference is, a datetime comparison will work as long as the last datetime is defined as being x hours after the first. Quote Link to comment Share on other sites More sharing options...
mierlp Posted September 24, 2020 Author Share Posted September 24, 2020 Indeed, no date is used because the times are seen as a reference framework. - morning period falls between 7 a.m. to 12 p.m. - afternoon falls between 12: 00-17: 00 - evening 17: 00-21: 00 - night between 21: 00: 02: 00 When filling the period times, a check must therefore be made to ensure that the start time is not greater than the end time. That goes well until you use hours in combination of BEFORE and AFTER 00:00 In the actual planning, someone selects a period and specifies a working time. It is then checked whether the specified working time falls within the period times. Maybe an option to use 2 dummy date fields that are not used in the software You will get something like: - start Date - startTime - endDate - endTime Dates are always the current date and when EndTime is> 00:00 then EndDate + 1 Using a DateTime field in it is again cumbersome to use ReplaceDate where you only change that date. Would be nice to have a time slider :) with begin/end time Regards Peter Quote Link to comment Share on other sites More sharing options...
mehamada Posted September 27, 2020 Share Posted September 27, 2020 System.DateUtils.CompareTime http://docwiki.embarcadero.com/Libraries/Sydney/en/System.DateUtils.CompareTime Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.