Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
danaleota1
Creator
Creator

casting a text/string to datetime value in the select statement

I'm working on an incremental and initial load for a QVD and I have a date value stored as a text that I want to convert to a datetime data type in the select statement before the load statement.  Any suggestions?  Thanks!

I've tried several things to convert it and so far none have worked I continue to get errors. I've tried all of the following:

//need to transform this to a date field
TRY_CAST("UDF_4_TXT" as datetime) as "UDF_4_TXT",
//CAST('12/01/2019' as date) as StringToDate,
//convert('12/01/2019', DATETIME) as StringToDate,
//cast("UDF_4_TXT"('YYYY-MM-DD HH:MM:SS', "YYYY-MM-DD HH:MM:SS") as DATETIME) as "UDF_4_TXT^",
//STR_TO_DATE("UDF_4_TXT" , 'YYYY-MM-DD HH:MM:SS') as "UDF_4_TXT^",
//TO_TIMESTAMP("UDF_4_TXT", 'YYYY-MM-DD HH:MM:SS') as "UDF_4_TXT^",
//CAST("UDF_4_TXT" AS DATETIME) as "UDF_4_TXT^",
//CONVERT("UDF_4_TXT", DATETIME) as "UDF_4_TXT^",
//convert("UDF_4_TXT", 'YYYY-MM-DD HH:MM:SS', 101) as "UDF_4_TXT^",

...

WHERE "UDF_4_TXT" >= '2021-11-01 00:00:00.000'

1 Reply
Or
MVP
MVP

I'd suggest asking in the appropriate forum for whatever type of database you're using, since anything done in the select query isn't actually related to Qlik. That said, your attempts (or at least some of them) look to be correct in syntax for most database types, so I'd suggest checking whether the values contained in the UDF_4_TXT field are all actually valid timestamps. If they are, posting the specific error you're getting would increase the odds of someone being able to help, too.