cancel
Showing results for 
Search instead for 
Did you mean: 

Convert varchar to date in sql instruction

fcorodriguezl
Contributor
0 Kudos

Hi everybody!

I have a scrip to execute a SQL instruction to get a max date, but my field StrDATE is like varchar(8). I need get the max value, but i dont know how to convert to date in sql instruction.

I try with something like this, but not works.

$G_UPDATE = sql('DB','select max(Strdate ) from tb01' );

Please somebody can help me.?

Thanks for your help.

View Entire Topic
xiaoming_wu
Participant
fcorodriguezl
Contributor
0 Kudos

Thanks Xia!

The problem is that apparently when I use the quotes in the sql to define format date 'yyyymmdd', for example:

$G_UPDATE = sql('DS','select max(to_date(DateStr,'yyyymmdd')) from tb01' );

When I check the syntax I get an error: "near <yyyymmdd> found <identifier> expecting < +,||..."

Regards.

xiaoming_wu
Participant
0 Kudos

Hi Francisco,

By using to_date() function, I mean you can use this function for the return value of sql(), like this $G_UPDATE=to_data(sql('DB','select max(Strdate ) from tb01' ), 'yyyymmdd').