# Sybase example queries

    1. select now=convert(char,getdate(),3)

    2. select datename(hour,getdate()),datename(minute,getdate()),
              datename(second,getdate())

    3. select getdate()

    6. select interval=datepart(year,"Nov 1 1993")+datepart(year,getdate())

    8. select convert(datetime,"1997-01-01",105)

    9. select convert(datetime,"12:34:56")

    10. select convert(datetime,"1997-01-01 12:34:56",105)

    11. select day=9,second=datepart(second,"23:45:12")

    13. select Birthday
        from birthdays
        where Birthday="Sep 15 1976"

    14. select Birthday
        from birthdays
        where Birthday<"Sep 15 1976"

    15. select Birthday
        from birthdays
        where Birthday<>"Sep 15 1976"

    16. select Birthday
        from birthdays
        where Birthday>"Sep 10 1976"  AND
              Birthday<"Sep 20 1976"

    17.  select date=getdate()
         where datepart(month,getdate())=datepart(month,"Dec 1 1950")

         select ID
         from intervals
         where (interval>10 AND type="SEC")
         OR (interval>0 AND type<>"SEC")

    21. select name
        from dates
        where birthday=NULL

    22. select ID
        from intervals
        where interval=NULL

    23. select Birthday
        from birthdays
        where Birthday<="Dec 31 1977" AND
        datepart(year,"Jan 1 1977")<=datepart(year,Birthday) + 1

    24. select dateadd(month,10,getdate())

    25+26. select datediff(month,getdate(),"Sep 1 1980")

    29. select datename(month,getdate()),datename(day,getdate()),
               datename(year,getdate())

        select convert(char(3),datename(month,getdate()))+" "
               +convert(char(2),datename(day,getdate()))+","
               +convert(char(4),datename(year,getdate()))

        select convert(char(2),datename(hour,getdate()))+":"
               +convert(char(2),datename(minute,getdate()))+":"
               +convert(char(2),datename(second,getdate()))

        select convert (datetime,
           (convert(char(3),datename(month,getdate()))+" "
           +convert(char(2),datename(day,getdate()))+","
           +convert(char(4),datename(year,getdate()))
           )
                       )

        select convert (datetime,
           convert(char(4),datename(year,getdate()))
           +"-"
           +convert (char(3),datename(month,getdate()))
           +"-"
           +convert(char(2),datename(day,getdate()))
           +" "
           +convert(char(2),datename(hour,getdate()))
           +":"
           +convert(char(2),datename(minute,getdate()))
           +":"
           +convert(char(2),datename(second,getdate()))
                       , 105
                       )

    31. select date=getdate()

    34+35.
        select months=datediff(month,"Apr 5 1997","May 9 1997")

    41. select convert(datetime,"1997-01-01",105)

    42. select datename(hour,convert(datetime,"1997-01-01 11:00AM",105))

    43. select convert(datetime,"1997-01-01",105)

    44. select convert(datetime,"12:00AM")

    47. select convert(char(30),getdate())

    53. select datename(day,getdate()

    Creating a period table:

    create table periods
    (
     periodID char(5) not null,
     p1 datetime not null,
     p2 datetime not null,
     constraint period_ID primary key
    	(periodID)
    )

    63. select periodID from periods
        where p1 = "Dec 15 1997" AND p2 = "Dec 30 1997"

    64. select periodID from periods
        where p2 < "Dec 15 1997"

    65. select periodID from periods
        where p1 > "Dec 30 1997"

    66. select periodID from periods
        where p1 = "Dec 30 1997"

    72. select periodID from periods
        where p1="Dec 15 1997" AND p2<"Dec 30 1997"

    74. select periodID from periods
        where p2="Dec 30 1997" AND p1>"Dec 15 1997"

    77. select periodID from periods
        where p1=NULL

    78. select p1 from periods

    79. select dateadd(day,-1,p1)
        from periods

    80. select dateadd(day,-1,p2)
        from periods

    81. select p2
        from periods

    82. select datediff(datepart,p1,p2) from periods

    84+85. select dateadd(day,5,p1),dateadd(day,5,p2)
        from periods

    87.
        select start="Dec 12 1997",end="Dec 13 1997"

    97.
        select convert(char(10),p1)+"-"+convert(char(10),p2)
               from periods