Subtracting 1 from a date value

  • Can you help me?

    I'm trying to write some script to retreive a date value and then subtract 1 day from this and store the new value in a table.  For example, 31/10/2006 -1 = 30/10/2006.

    I know how to save the value once it is calculated, but don't know which calculation to use the acheive what I want.

    Any help is greatfully received.

     

  • DATEADD(day, -1, '31/10/2006')

    Far away is close at hand in the images of elsewhere.
    Anon.

  • select Cast('31/Oct/2006' as datetime) -1 would work too.

  • quoteBut you also need to look up the ISO-8601 format for temproal data so you will not use a local dialect

    Yes, I forgot to mention the format of the date for conversion

    quoteStandard SQL uses only "yyyy-mm-dd"

    The only unambiguous format is yyyymmdd whereas nnnn-nn-nn (even if deemed to be yyyy-mm-dd) can be interpreted as yyyy-mm-dd or yyyy-dd-mm depending on the language settings of the login. SQL Server's default is the American format of yyyy-dd-mm.

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply