Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATETIME()

Status
Not open for further replies.

LouisC4

Programmer
Jul 26, 2003
54
US
Hi all,

How can I add or subtract Hours or Minutes from a DateTime variable?

Example: x = DATETIME(2005, 3, 24, 10, 45, 22)

if I wanted to subtract 45 minutes from x to get the result of 3/24/2005 10:00:22, how is this achieved?

also,

is there a way to subtract 1 day from x to get 3/23/2005 10:45:22?

TIA,

Louis
 
Loius,

I think you have to subtract seconds. So to subtract 45 minutes I would subtract 2700 (x-2700). That's the way I do it anyway.


Hope that helps,

Stewart
PS If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Louis,

Datetime arithmetic is in seconds, so for example to subtract 45 minutes from the current date/time:

?DATETIME() - 60 * 45

To subtract a day:

?DATETIME() - 60 * 60 * 24

Jim
 
Thanks Stewart and Jim, that is very helpful.

Very simple :)

Louis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top