Solved

formatting for Y2K

Posted on 1998-08-08
6
179 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now