Solved

formatting for Y2K

Posted on 1998-08-08
6
214 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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.
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…

828 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