Home > Back-end >  SQL get CreatedDate = 2 days ago
SQL get CreatedDate = 2 days ago

Time:12-21

I'm trying to achieve the following with SFMC. I want to filter records from a Data extension to populate a new data extension with every record that was created two days ago (irrespective of the time during that day).

The CreatedDate is the field that needs to be filtered and the date format is: MM/DD/YYY HH:MM:SS AM

The pseudo code is:

Select *
From ent.Lead
Where CreatedDate = 2 days ago

How should the right code look like?

CodePudding user response:

Depends on the DB you are using, but try this.

Select *
From ent.Lead
Where CreatedDate = sysdate - 2;

CodePudding user response:

Depends on the DB type for sure, but PostgreSQL it would look something like:

Select *
From ent.Lead
Where CreatedDate between dateadd ('days', -2, to_date(current_date)) and current_date
  • Related