Search code examples
sap-ase

find the difference between two date values in Sybase database


I have understand that there are some functions days() in sybase iq, but in sybase ase, I think we have only date part option to get the number of days between two days.

My requirement is that i want number days between two days without comparing month or year between two days.

Any help appreciated!


Solution

  • Use datediff function:

    Description

    Calculates the number of date parts between two specified dates or times.

    Syntax

    datediff(datepart, {date, date | time, time | bigtime, bigtime | datetime, datetime | bigdatetime, bigdatetime}]) Parameters

    datepart is a date part or abbreviation. For a list of the date parts and abbreviations recognized by Adaptive Server, see Transact-SQL Users Guide.

    date expression1 is an expression of type datetime, smalldatetime, bigdatetime, bigtime, date, time, or a character string in a datetime format.

    date expression2 is an expression of type datetime, smalldatetime, bigdatetime, bigtime, date, time, or a character string in a datetime format.

    Example 6

    Finds the number of days between two times:

    declare @a time
    declare @b time
    select @a = "20:43:22"
    select @b = "10:43:22"
    select datediff(dd, @a, @b)
    -----------
         0