Solved

formatting for Y2K

Posted on 1998-08-08
6
202 Views
Last Modified: 2010-04-30
I am currently using the Lost_Focus event in a textbox and formatting the date as:
Format(y2kcheck$, "m/d/yyyy"), but if the user enters 03/03/00 the output is 3/3/1900,
How can I change the code to make it 3/3/2000?
Code please...
0
Comment
Question by:dtucker
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:percosolator
ID: 1468314
What version of VB are you using (VB5 SP3, here)

Tried the following in the immediate window:

?format("03/03/00","mm/dd/yyyy")
03/03/2000

Put it at 2000, for me.  Any other information?
0
 

Author Comment

by:dtucker
ID: 1468315
I am using vb4 16 bit.
I could even break down the date and replace 1900 with 2000 if there is not a FORMATing way to do it.
Code Please...
Thank you for your prompt response.
Dave
0
 
LVL 2

Expert Comment

by:percosolator
ID: 1468316
What we are seeing here is inherent behavior designed into the date datatype.

My understanding of how Microsoft decided to handle 2-digit years, was this.

any 2-digit year from 00 to 29 is considered 20th century (i.e. 2000, 2019, 2029)

any 2-digit year from 30 to 99 is considered 19th century (i.e. 1930, 1968, 1999)

(Tested them out here, and it worked as expected)

Try these examples (00,29,30,99) out and please post your results.  That will help us see what's going on to better solve your dilemma.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 6

Expert Comment

by:clifABB
ID: 1468317
Also, what database are you using?  Perhaps the database isn't Y2K compliant?
0
 

Author Comment

by:dtucker
ID: 1468318
My database is just a random file database, which isn't Y2K compliant.
if I type 3/3/00 I get 3/3/1900
if I type 3/3/30 I get 3/3/1930
So I have to find a way to check for the 00 in my date field and translate that to 2000, as well as 01 as 2001 etc.
Right now if someone types in 3/12/98 it returns 3/12/1998, so all is fine until the year 2000.
Any thought as how to do the check and conversion in vb4 16-bit?
0
 
LVL 2

Accepted Solution

by:
percosolator earned 50 total points
ID: 1468319
Here is some sample code that I tested and believe will help you with your problem.

Put this code and put it in a test project.  If you have any questions, please post them.

-------------------------------------------------

Option Explicit

Private Sub Form_Load()

    MsgBox FixDate(CDate("1/1/00"))
    MsgBox FixDate(CDate("1/1/01"))
    MsgBox FixDate(CDate("1/1/99"))
   
    MsgBox FixDate(CDate("3/3/29"))
    MsgBox FixDate(CDate("3/30/30"))
    MsgBox FixDate(CDate("2/3/68"))
End Sub
Private Function FixDate(Date_ As Date) As String

    Dim strYear As String, _
        strDay As String, _
        strMonth As String
   
   
    strYear = Format(Date_, "yyyy")
    strMonth = Format(Date_, "mm")
    strDay = Format(Date_, "dd")
   
    If (strYear < "1930") Then strYear = strYear + 100
   
    FixDate = Format(strMonth & "/" & strDay & "/" & strYear, "mm/dd/yyyy")
       
End Function

------------------------------------
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question