0

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!

phpcfm
  • 87
  • 8
mahesh
  • 1,523
  • 4
  • 23
  • 39

1 Answers1

1

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
333kenshin
  • 1,995
  • 12
  • 17
  • 2
    Word of warning - at least in ASE 15.7, the datediff() function does not work as documented when using the datepart for year (yy). Specifically, while datediff(mm, '12/30/2018', '1/2/2019') will correctly return 0, datediff(yy, '12/30/2018', '1/2/2019') will return 1. It appears that if the datepart is set to yy, the function only compares the year parts of the two dates, and ignores the rest. (Documentation states that the result should be truncated if the difference is fractional, which works for other dateparts, but not for yy.) – Sean Worle Mar 26 '19 at 16:14