Search code examples
sybase

Sybase - Strip off hour, minutes and seconds


I have this datetime:

09/29/2012 08:23:00.65

How can I just have this, using sybase:

09/29/2012

UPDATE:

How can I transform date '16-01-2017' into 20170116?


Solution

  • Use convert(date, <your-datetime-field>)

    For example:

    select convert(date, '09/29/2012 08:23:00.65')
    

    Returns:

    09/29/2012

    Edit per your comment
    The code above works for me, but you can use the following as well:

    SELECT CONVERT(char(10), '09/29/2012 08:23:00.65', 101)
    

    Edit per your update
    First, I suggest that you have a look here at sybase documentation for convert

    Second it can be achieved like this:

    select convert(char(10), convert(datetime, '16-01-2017',105), 112)