Cancel
Showing results for 
Search instead for 
Did you mean: 

checking time of datetime in method

Creator
Creator

Hi everybody,

im trying to make a conditional method which checks the time of a datetime value.
I have datetimes listed in a tablefile, i'd like the method to check if the datetime is between two values, lets say between 09:00 and 19:00.

Is there a way to make this comparison, and does it involve conversion?

The context would be something like this

IF datetimetable[1,currentrow] < 19:00 AND datetimetable[1,currentrow] > 09:00 THEN
--perform some action
ELSE

--perform some action
END;

 

the problem is obviously that in the datetimetable that the format(datetime) is not equal to the format(time) that it is trying to check.

Any suggestions how to overcome this?

3 REPLIES 3

Re: checking time of datetime in method

Siemens Phenom Siemens Phenom
Siemens Phenom

please check help for timeOfDay


Regards

Always consider using the AttributeExplorer!

Re: checking time of datetime in method

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi TPSuser,

 

you can use the functions str_to_time, str_to_date and str_to_datetime to convert a date/time represented as a string to a time, datetime or date.

In your specific case you mention that you have datetimes and want to compare to a specific time.

For this you can use the timeOfDay function.

 

So your code would look something like:

if timeOfDay(datetimetable[1,currentrow]) < str_to_time("19:00") ...

 

If you execute the code in a loop it might make sense to assign the time to a local variable to increase performance:

local t19:time := str_to_time("19:00");

 

 

Regards,

Ralf

 

 

Regards,

Ralf
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: checking time of datetime in method

Creator
Creator

@Eventdebugger, thx! timeOfDay was exactly what I was looking for.

@RalfTobel, your explanation made it very clear, it helped me a lot! Smiley Happy