Expand my Community achievements bar.

Date in a string field

Avatar

Level 2

Hi,

I need to use a date stored in a string field to do some queries.

 

In the specific case, I need to select contacts 10 days before a policy expiration date.

The expiration date is stored in a string field so I can't use the formula SubDays(,).

Is it possible to read the string field as a date? I use ToDateTime but doesn't work.

 

Thanks

E.

8 Replies

Avatar

Community Advisor

Hi @ElisabettaPi ,

Considering your string field has date format as MM/DD/YYYY, You can use DaysDiff() functionality instead of SubDays().

In Query, To fetch recipients who has policy expiration date after 10th day, add the condition as below

 

DaysDiff(ToDateTime(@your_string_field),DateOnly(GetDate()) ) EQUALS TO 10

 

ParthaSarathy_0-1719572552040.png

Avatar

Level 2

Hi,

thanks for your answer.

 

I tried your solution but it didn't work.

The error is: Invalid input syntax for type timestamp: "       ".

The string date has this format "2024-08-27" without time, it is a text field.

I don't know if you have other suggestion for me.

 

Thanks a lot.

E.

Avatar

Community Advisor
DaysDiff(ToDateTime(@stringField),DateOnly(GetDate()) )

@ElisabettaPi , The Same worked fine for me with date format as 2024-08-27 .  

Avatar

Level 1

Hi @ElisabettaPi 

 

Try to use "expiration date equal to  DaysDiff( GetDate() -10 , 0)".

Avatar

Level 2

I tried but the error is the same specified in the comment above.

Avatar

Employee

@ElisabettaPi which RDBMS you are using for Campaign database or for the table where this string field is stored?