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. How not to string a date

How not to string a date

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpc++help
2 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.
  • P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #1

    Here's another chunk of C++ that has been converted to VB.net:

    Public Shared Function Strdate(ByVal dateBuf As String) As String
        '    timt(tnow)
        'tm     \*tnowVals
        'time(&tnow)
        'tnowVals = localtime(&tnow)
        Dim tnowVals As DateTime = DateTime.Now
    
        tnowVals = DateTime.Now
    
        If tnowVals.Year > 1999 Then 'If (tnowVals.tm\_year > 99) Then
            tnowVals.Subtract(TimeSpan.FromDays(365 \* 100)) ' tnowVals.tm\_year -= 100
        End If
    
        dateBuf = tnowVals.ToString("MM/dd/yy") 'sprintf(dateBuf, "%02.02d/%02.02d/%02.02d", tnowVals.tm\_mon + 1, tnowVals.tm\_mday, tnowVals.tm\_year)
    
        Return dateBuf
    End Function
    

    Notice that even the original C++ is faulty; it should use % (mod) rather than subtracting 100 years -- a Y3K bug. :sigh:

    M 1 Reply Last reply
    0
    • P PIEBALDconsult

      Here's another chunk of C++ that has been converted to VB.net:

      Public Shared Function Strdate(ByVal dateBuf As String) As String
          '    timt(tnow)
          'tm     \*tnowVals
          'time(&tnow)
          'tnowVals = localtime(&tnow)
          Dim tnowVals As DateTime = DateTime.Now
      
          tnowVals = DateTime.Now
      
          If tnowVals.Year > 1999 Then 'If (tnowVals.tm\_year > 99) Then
              tnowVals.Subtract(TimeSpan.FromDays(365 \* 100)) ' tnowVals.tm\_year -= 100
          End If
      
          dateBuf = tnowVals.ToString("MM/dd/yy") 'sprintf(dateBuf, "%02.02d/%02.02d/%02.02d", tnowVals.tm\_mon + 1, tnowVals.tm\_mday, tnowVals.tm\_year)
      
          Return dateBuf
      End Function
      

      Notice that even the original C++ is faulty; it should use % (mod) rather than subtracting 100 years -- a Y3K bug. :sigh:

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      PIEBALDconsult wrote:

      a Y3K bug

      :laugh: ...there shall be no computers to run such a program on in the year 3000

      Illogical thoughts make me ill

      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