date search in SQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bhari
    New Member
    • Jun 2007
    • 1

    date search in SQL

    Hi all,
    I need to search for a date field in 'MM-DD-YYYY' format..
    any suggestions for this???
    MY field is of datetime type...is this okay for the above format to search..
  • Axlin
    New Member
    • Jun 2007
    • 2

    #2
    Hi.Your post is a little bit unclear.
    Try this function to get your date time format

    SELECT GETDATE();
    GO

    GETDATE() functions get today's date and time. execute the above statement in sql and you'll see the result.

    You can type in 'Date' under Look For: in the Help>Index inside the SQL Server 2005 management studio and it will retrieve all the functions you need related to date time.

    Gdluck!

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      Originally posted by Bhari
      Hi all,
      I need to search for a date field in 'MM-DD-YYYY' format..
      any suggestions for this???
      MY field is of datetime type...is this okay for the above format to search..
      Use the substring, concatenation, and cast features of SQL to reorganize your date field to how SQLServer expects it.

      Comment

      • zbychbor
        New Member
        • Jul 2007
        • 2

        #4
        Hi,

        why this format? I think better is YYYY-MM-DD (but you can use own format)
        try with example:

        select * from XXX where convert(varchar (10), [Field], 120) = '2001-12-30'

        when you want dateformat mm-dd-yyyy you should make some variations, like

        select * from XXX where
        right(convert(v archar(10), [Field], 120),2)+'-'+
        left(right(conv ert(varchar(10) , [Field], 120),5),2)+'-'+
        left(convert(va rchar(10), [Field], 120),4)
        = '30-12-2001'




        greatings
        Zibi

        Comment

        Working...