Skip to Content
avatar image
Former Member

Convert varchar to date in sql instruction

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Nov 24, 2017 at 09:22 AM

    $G_UPDATE = sql('DB','select max(Strdate ) from tb01' ); ---- >$G_UPDATE this variable should be varchar

    This will give max data and will be store in the variable $G_UPDATE

    Now create a new global variable $G_MAX_STR_DATE and in the same BODS script write

    $G_MAX_STR_DATE=to_date($G_UPDATE,'YYYYMMDD')

    or directly write

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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thanks Ravi,

      I tried to do it in one instruction but I could not. Anyway, your suggestion worked very well.

      Regards.

  • Nov 24, 2017 at 03:02 AM
    Add comment
    10|10000 characters needed characters exceeded