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. Other Discussions
  3. The Weird and The Wonderful
  4. Why is dates so difficult?

Why is dates so difficult?

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
4 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.
  • J Offline
    J Offline
    Jan Steyn
    wrote on last edited by
    #1

    DECLARE @Month VARCHAR(2), @Year VARCHAR(4)
    IF (month(GETDATE())) = 1
    BEGIN
    Set @Month = MONTH(DateAdd(month, -1, GETDATE()));
    Set @Year = YEAR(DateAdd(month, -1, GETDATE()));
    END
    ELSE
    BEGIN
    Set @Month = MONTH(GETDATE()) -1
    Set @Year = YEAR(GETDATE())
    END

    I just shook my head... It could have been done as easily as:

    DECLARE @Month VARCHAR(2), @Year VARCHAR(4)
    Set @Month = MONTH(DateAdd(month, -1, GETDATE()));
    Set @Year = YEAR(DateAdd(month, -1, GETDATE()));

    A J 2 Replies Last reply
    0
    • J Jan Steyn

      DECLARE @Month VARCHAR(2), @Year VARCHAR(4)
      IF (month(GETDATE())) = 1
      BEGIN
      Set @Month = MONTH(DateAdd(month, -1, GETDATE()));
      Set @Year = YEAR(DateAdd(month, -1, GETDATE()));
      END
      ELSE
      BEGIN
      Set @Month = MONTH(GETDATE()) -1
      Set @Year = YEAR(GETDATE())
      END

      I just shook my head... It could have been done as easily as:

      DECLARE @Month VARCHAR(2), @Year VARCHAR(4)
      Set @Month = MONTH(DateAdd(month, -1, GETDATE()));
      Set @Year = YEAR(DateAdd(month, -1, GETDATE()));

      A Offline
      A Offline
      AspDotNetDev
      wrote on last edited by
      #2

      Better yet:

      DECLARE @Month varchar(2), @Year varchar(4), @LastMonth datetime
      SET @LastMonth = DateAdd(MONTH, -1, GetDate())
      SET @Month = Month(@LastMonth)
      SET @Year = Year(@LastMonth)

      EOL

      1 Reply Last reply
      0
      • J Jan Steyn

        DECLARE @Month VARCHAR(2), @Year VARCHAR(4)
        IF (month(GETDATE())) = 1
        BEGIN
        Set @Month = MONTH(DateAdd(month, -1, GETDATE()));
        Set @Year = YEAR(DateAdd(month, -1, GETDATE()));
        END
        ELSE
        BEGIN
        Set @Month = MONTH(GETDATE()) -1
        Set @Year = YEAR(GETDATE())
        END

        I just shook my head... It could have been done as easily as:

        DECLARE @Month VARCHAR(2), @Year VARCHAR(4)
        Set @Month = MONTH(DateAdd(month, -1, GETDATE()));
        Set @Year = YEAR(DateAdd(month, -1, GETDATE()));

        J Offline
        J Offline
        John Hunley
        wrote on last edited by
        #3

        A better question is, why are grammar so difficult?

        F 1 Reply Last reply
        0
        • J John Hunley

          A better question is, why are grammar so difficult?

          F Offline
          F Offline
          Florin Jurcovici 0
          wrote on last edited by
          #4

          You mean, why is grammars for naturals language so difficults, right? ;P Well, one explanation could be that the speaker is not a native speaker. But I agree, I'm annoyed by bad grammar too.

          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