 ShowAll Questionssorted byDate Posted tzuvy

# Subtract 5 hours from a Date / Time field

Hi,

I'm creating a date / time formula field in which I would like to keep te time of another date time field and subtract five hours from it.

For example, in field A I would have "11/23/2010 9:03 PM" and in field B (the formula one I should see "11/23/2010 4:03 PM"

Is this possible?

Thanks

Tzuvy Best Answer chosen by Admin (Salesforce Developers)  Imran Mohammed

Use this formula.

fieldA - (1/4.8)

Let me know if you find any issues. Imran Mohammed

yes, thats possible.

fieldA - 5  should do the job for fieldB Imran Mohammed

Hey sorry, i misunderstood your question. Imran Mohammed

Use this formula.

fieldA - (1/4.8)

Let me know if you find any issues.

This was selected as the best answer tzuvy

Thanks!!

It works perfectly.

Cheers

Tzuvy JPlayEHR

Just in case anybody else was wondering (i.e. you need to subtract or add more or less than 5 hours) 1/4.8 = 5 hours because it is taking 1 day and dividing it by the quotient of 24hours / number of hours. 24 / 5 = 4.8 or 24/4 = 6 (1/6) .  4 hours is 1/6th of a day.  5 hours is 1/4.8th of a day. Rahul1

Instead of (1/6) You have to use (DateTime - (1/6.0)) for 4 hrs subtraction
(DateTime - (1/8.0)) for 3 hrs subtraction
(DateTime - (1/12.0)) for 2 hrs subtraction
(DateTime - (1/24.0)) for 1 hrs subtraction

have a nice day!! AruAru
How can we substract 5 minutes from DateTime.
DateTime d = (System.now()- ((24/1440.0)/5.0)) will it work?