Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Date comparison

Date comparison

Scheduled Pinned Locked Moved Database
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TariqMahmood
    wrote on last edited by
    #1

    i want to company that if today date is greater than do step 1 and if not than do step 2 and i m doing this IF dbo.FormatDate(GETDATE()) > dbo.FormatDate('28/04/2006') --Step 1 ELSE --Step 1 but its not proper working i can do this with year, month and day individual comparison buts not proper way to acheive task. can anyone tell me that what's the mistake in above code:) dbo.FormatDate() is a function which extract only date from date and time. Thanks

    C 1 Reply Last reply
    0
    • T TariqMahmood

      i want to company that if today date is greater than do step 1 and if not than do step 2 and i m doing this IF dbo.FormatDate(GETDATE()) > dbo.FormatDate('28/04/2006') --Step 1 ELSE --Step 1 but its not proper working i can do this with year, month and day individual comparison buts not proper way to acheive task. can anyone tell me that what's the mistake in above code:) dbo.FormatDate() is a function which extract only date from date and time. Thanks

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      I'm guessing (becuase you've not provided the code) that FormatDate is a UDF that returns some value that you can test against. I don't know why you need to do this as you can check greater than/less than on a date already.

      IF GETDATE() > '2006-04-28'
      BEGIN
      -- Do stuff
      END
      ELSE
      BEGIN
      -- Do other stuff
      END

      I would recommend that you always use ISO dates (YYYY-MM-DD) - that way you don't get messed around with cultural specific problems. ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?

      T 1 Reply Last reply
      0
      • C Colin Angus Mackay

        I'm guessing (becuase you've not provided the code) that FormatDate is a UDF that returns some value that you can test against. I don't know why you need to do this as you can check greater than/less than on a date already.

        IF GETDATE() > '2006-04-28'
        BEGIN
        -- Do stuff
        END
        ELSE
        BEGIN
        -- Do other stuff
        END

        I would recommend that you always use ISO dates (YYYY-MM-DD) - that way you don't get messed around with cultural specific problems. ColinMackay.net Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?

        T Offline
        T Offline
        TariqMahmood
        wrote on last edited by
        #3

        Thanks for ur comments i have solved the problem with this code SET Dateformat dmy IF GETDATE() > dbo.FormatDate('24/04/2006') BEGIN PRINT 'A' END ELSE BEGIN PRINT 'B' END Thanks Best Regards, Tariq Mahmood

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups