function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jonathan CzarJonathan Czar 

How do I find all Contacts created in the last hour?

I am writing a SOQL in DataLoader to pull all Contacts created in the last hour.  However, I cannot find any date function to use.  I tried CREATEDDATE >=LAST_N_DAYS:0.0417, but it only accepts integers.  Is there a function I can use?

 

Thanks in advance
PS Sorry if I put this in the wrong topic group.  I was not sure where it would go.  This is my first posted question.

Matt Eck 15Matt Eck 15
If this is just being ran in dataloader you can set up your query like this:
SELECT Id, CreatedDate FROM Contact WHERE CreatedDate >= 2019-02-27T12:00:00Z
Updating the time to fit within the last hour.

Hope this helps.
Jonathan CzarJonathan Czar
Thanks for the response.  I want to schedule this report to run every hour, so the datetime has to be dynamic.
Raj VakatiRaj Vakati
Try like this
 
DateTime currentTime = System.now();

DateTime cutOff = currentTime.addHours(-2);
 Database.getQueryLocator([SELECT Id, CreatedDate FROM Contact WHERE CreatedDate 
                 CreatedDate >= :cutOff ]);

 
Deepali KulshresthaDeepali Kulshrestha
Hi Jonathan,

If you want to get all the contacts that are created in last one hour you can use this query.
datetime dt = datetime.newInstance(system.today().year(),system.today().month(),system.today().day(),system.now().hour()-1,  0, 0);
List<Contact> conList=[select id,name from Contact where createdDate>: dt];

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha