Please can someone show me how to calculate the number of seconds between 2 time points.
i.e the difference in seconds between Bar and Bar?
The datetime type is intended for storing the date and time as the number of seconds elapsed since January 01, 1970. This type occupies 8 bytes of memory. This is fine but how do you display Time in seconds as opposed to datetime format? So Print(Time) gives 2014.10.15 04:00:00?
The DateTime function is always baffling!!
thanks for any replies.
Just subtract the 2 times from one another:
printf("The time difference in seconds between Bar 0 and Bar 10 is %i", Time-Time);
You might want to take a look at type casting and also how Print works "Dates are shown as YYYY.MM.DD HH:MI:SS. To show data in another format, use TimeToString(). "
If there is only one Print argument, and it is a date, it will use the default display of YYYY.MM.DD HH:MI:SS.... the value is stored as seconds since the start of 1970 however.
If the only argument is a calculated date, it still gives the difference in seconds converted back to a date again... so 10 minutes after 01 Jan 1970.
If you mix arguments in a Print statement, and not all of them are strings, you will now get a warning but again the difference in seconds will be printed as a date (the default handling of a datetime):
Print("The time difference in seconds between Bar 0 and Bar 10 is " + (Time-Time));
To get rid of the warning and give the "expected" result, you can use:
Print("The time difference in seconds between Bar 0 and Bar 10 is " + IntegerToString(Time-Time));
Which is the same as:
printf is just an abbreviated way to write PrintFormat
To add comments, please log in or register