Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    24

    Unanswered: Convert char to datetime

    Hi,

    I have a record with char as datatype in sybase. I want to convert it to datatime datatype. eg.
    the value as char is 1992Q1 "where Q1 is first quarter" to be converted as 19920331 (march 31)
    and for 1992Q2 where Q2 is second quarter as 19920630 (June 30)
    for 1992Q3 as 19920930, for 1992Q4 as 19921231

    If any one can send me the update statement for this that will be appreciated.
    Thanks
    Srinivas chityala

  2. #2
    Join Date
    Nov 2002
    Location
    Switzerland
    Posts
    524
    Something like
    Code:
    UPDATE MyTable
    SET MyDate = convert(datetime, substring(MyDate,1, 4)+"/3/31"
    WHERE Mydate like "%Q1"
    
    UPDATE MyTable
    SET MyDate = convert(datetime, substring(MyDate,1, 4)+"/6/30"
    WHERE Mydate like "%Q2"
    
    UPDATE MyTable
    SET MyDate = convert(datetime, substring(MyDate,1, 4)+"/9/30"
    WHERE Mydate like "%Q3"
    
    UPDATE MyTable
    SET MyDate = convert(datetime, substring(MyDate,1, 4)+"/12/31"
    WHERE Mydate like "%Q4"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •