Search code examples
sybaseamos

Create a timestamp from separate date and time integers


I'm trying to create a from - to datetime range from fields in a database table.

Unfortunately the fields aren't saved as a timestamp.

I have two entries

  • time in hours from midnight
  • date in days from 1 jan 1970

Is there a command to combine these entries so i can use a select statement and search in a range of time?

My database is sybase 15.7


Solution

  • I tried some options aswell, and this one seems to work for me:

    CONVERT(
       VARCHAR,
       DATEADD(
          DAY,
          time_captured.end_date,
          `DEC 31 1971`
       ),
       104
    ) || `` || RIGHT(
       `00` || CONVERT(
          VARCHAR,
          FLOOR(time_captured.end_time/60)
       ),
       2
    ) || `:` || RIGHT(
       `00` + CONVERT(
          VARCHAR,
          time_captured.end_time%60
       ),
       2
    ) || `:00` >= CONVERT(
       VARCHAR,
       DATEADD(
          DAY,
          sp.start_date,
          `DEC 31 1971`
       ),
       104
    ) || `` || RIGHT(
       `00` || CONVERT(
          VARCHAR,
          FLOOR(sp.start_time/60)
       ),
       2
    ) || `:` || RIGHT(
       `00` + CONVERT(
          VARCHAR,
          sp.start_time%60
       ),
       2
    ) || `:00`
    

    The way this database is made is quite weird. Thanks for all your answers!