[SalesForce] last 24 hrs of date field

I want to query last 24 hrs of Date field in my custom object.
But when I debug the value, they become like that.

Example : Date.today() : 2013-10-04 00:00:00

last24hrs : 2013-10-03 00:00:00

So totally,no current time of query made is used. Now it is like I am querying for since yesterday results. Date.today().addDays(-1);

My requirement is using hour,min,second too. But the custom field is only Date.
Example if I make query at 2013/10/04 13:00 , then the result of since 2013/10/03 13:00 should appear. before 13:00 hr results should not come out.

How should I approach this issue?

Best Answer

So you want to be able to query an object where a date has a date time value within the last 24 hours?

I think that you need to change your field from date to datetime if you want to get that data.

It's hard to tell exactly what you are doing wihout seeing your code but maybe try using system.now() instead of date.today() // OR datetime.now() either way

Run this in execute anon to see what I mean

  Date TodayDate = date.today();
  DateTime NowDate = datetime.now();
  DateTime Past24 = system.now().AddDays(-1);

  system.debug('OriginalDate::' + TodayDate);
  system.debug('NowDate::' + NowDate);
  system.debug('Past24::' + Past24);

If that doesn't help please post your code.

Related Topic