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. Datetime format checking in SQL server stored procedure

Datetime format checking in SQL server stored procedure

Scheduled Pinned Locked Moved Database
databasecsharpsql-serversysadmintutorial
5 Posts 4 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.
  • D Offline
    D Offline
    Danpeking
    wrote on last edited by
    #1

    Hi, I am wondering if there is a way of proofing a stored procedure in terms of the datetime localisation. For example, in the C# we may use the web.config or machine.config to set the application's localised date settings:

    globalization uiCulture="en" culture="en-GB">

    This helps when we do a date comparison in a static class of ours to return a certain rating factor. Is there an equivalent way of us checking whether or not the date we pass into the stored procedure is in e.g. UK format and will be compared against our dates in the UK format too? We have 2 datetime columns, DateEffectiveFrom and DateEffectiveTo in our table and we use those dates to compare with the date passed in to return the relevant data. Thanks

    D L J 3 Replies Last reply
    0
    • D Danpeking

      Hi, I am wondering if there is a way of proofing a stored procedure in terms of the datetime localisation. For example, in the C# we may use the web.config or machine.config to set the application's localised date settings:

      globalization uiCulture="en" culture="en-GB">

      This helps when we do a date comparison in a static class of ours to return a certain rating factor. Is there an equivalent way of us checking whether or not the date we pass into the stored procedure is in e.g. UK format and will be compared against our dates in the UK format too? We have 2 datetime columns, DateEffectiveFrom and DateEffectiveTo in our table and we use those dates to compare with the date passed in to return the relevant data. Thanks

      D Offline
      D Offline
      David Skelly
      wrote on last edited by
      #2

      Just to clarify one thing: if your columns are datetime columns, why do you need to worry about date formats? You can just compare one datetime with another. Is the parameter to the stored proc being passed as a string/varchar and you need to figure out what format it is in order to do the comparison?

      D 1 Reply Last reply
      0
      • D Danpeking

        Hi, I am wondering if there is a way of proofing a stored procedure in terms of the datetime localisation. For example, in the C# we may use the web.config or machine.config to set the application's localised date settings:

        globalization uiCulture="en" culture="en-GB">

        This helps when we do a date comparison in a static class of ours to return a certain rating factor. Is there an equivalent way of us checking whether or not the date we pass into the stored procedure is in e.g. UK format and will be compared against our dates in the UK format too? We have 2 datetime columns, DateEffectiveFrom and DateEffectiveTo in our table and we use those dates to compare with the date passed in to return the relevant data. Thanks

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        date formatting is a human thing, it does not relate to databases at all, unless you make a mistake. What you should do is define datetime fields, and pass DateTime SQLParameters, that avoids all datetime formatting issues on the DB side; obviously you still have to deal with the datetime formatting in the GUI, however that is the only place it should matter (and there you should follow the system's regional settings). :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        1 Reply Last reply
        0
        • D Danpeking

          Hi, I am wondering if there is a way of proofing a stored procedure in terms of the datetime localisation. For example, in the C# we may use the web.config or machine.config to set the application's localised date settings:

          globalization uiCulture="en" culture="en-GB">

          This helps when we do a date comparison in a static class of ours to return a certain rating factor. Is there an equivalent way of us checking whether or not the date we pass into the stored procedure is in e.g. UK format and will be compared against our dates in the UK format too? We have 2 datetime columns, DateEffectiveFrom and DateEffectiveTo in our table and we use those dates to compare with the date passed in to return the relevant data. Thanks

          J Offline
          J Offline
          Jorgen Andersson
          wrote on last edited by
          #4

          Luc's answer is still valid as the correct way of doing things, but if you want to pursue the hard way you can start looking here[^] for SQL Server.

          "When did ignorance become a point of view" - Dilbert

          1 Reply Last reply
          0
          • D David Skelly

            Just to clarify one thing: if your columns are datetime columns, why do you need to worry about date formats? You can just compare one datetime with another. Is the parameter to the stored proc being passed as a string/varchar and you need to figure out what format it is in order to do the comparison?

            D Offline
            D Offline
            Danpeking
            wrote on last edited by
            #5

            Hi David, the parameter will be a datetime. I need to find which date range this falls in. For example, I pass in the date 11/11/2010 and the columns are: ID StartEffDate EndEffDate Rate 1 01/01/2000 31/12/2003 1.05 2 01/01/2004 31/03/2011 1.15 3 01/04/2011 01/01/2012 1.25 I need to return the appropriate Rate, e.g. in this case 1.15

            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