Solved

formatting for Y2K

Posted on 1998-08-08
6
192 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 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

25 Experts available now in Live!

Get 1:1 Help Now