PC Review


Reply
Thread Tools Rate Thread

Convert 2-digit year

 
 
Hennie Neuhoff
Guest
Posts: n/a
 
      24th Aug 2009
Hi. All,
Easy one for the experts.
My country use a unique [13 number-digit] Identification system.
The first 6-digits represent the date of birth [yymmdd]
In my code the ID number is entered on a userform as text and
displayed as follows 52-02-08-5034-087 [in this example the d.of b
is 8-Feb-1952]
Range("Bithday").Value = Left(Idnumber, 8)
displays the required birthday in Range("Bithday")
With the note "This cell contains a date string represented with
only 2 digits for the year."
If I select the option "Convert XX to 19XX" it gives me exactly
what I want.
I tried macro record but it doesn’t give me any result.
How do I include the "Convert XX to 19XX" in my code ?

--
HJN
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      24th Aug 2009
You added two more character to the string when you chaged the year from two
digits to 4 digits

from
Range("Bithday").Value = Left(Idnumber, 8)
to
Range("Bithday").Value = Left(Idnumber, 10)

You will either get
52-02-08-5034-087 : 17 characters
or
52-02-2008-5034-087 : 19 characters


Os the code would look like this

if len(IdNumber) = 17 then
Range("Bithday").Value = Left(Idnumber, 8)
else
Range("Bithday").Value = Left(Idnumber, 10)
end if
"Hennie Neuhoff" wrote:

> Hi. All,
> Easy one for the experts.
> My country use a unique [13 number-digit] Identification system.
> The first 6-digits represent the date of birth [yymmdd]
> In my code the ID number is entered on a userform as text and
> displayed as follows 52-02-08-5034-087 [in this example the d.of b
> is 8-Feb-1952]
> Range("Bithday").Value = Left(Idnumber, 8)
> displays the required birthday in Range("Bithday")
> With the note "This cell contains a date string represented with
> only 2 digits for the year."
> If I select the option "Convert XX to 19XX" it gives me exactly
> what I want.
> I tried macro record but it doesn’t give me any result.
> How do I include the "Convert XX to 19XX" in my code ?
>
> --
> HJN

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      24th Aug 2009
You can let VB handle putting in the century for you using this code line...

Range("Bithday").Value = CDate(Mid(IDnumber, 7, 3) & MonthName(Mid( _
IDnumber, 4, 2)) & "-" & Left(IDnumber, 2))

HOWEVER, the point at which VB switches from the 1900s to the 2000s is
determined by the Windows' Regional Settings (which can be changed by the
user). The default breakpoint is 1930... a 2-digit year before 30 will be in
the 2000s (for example, 29 would become 2029 whereas a 2-digit year of 30 or
later would be placed in the 1900 (for example, 30 would become 1930).

--
Rick (MVP - Excel)


"Hennie Neuhoff" <(E-Mail Removed)> wrote in message
news:065AAD99-D9DA-4EE4-A7D6-(E-Mail Removed)...
> Hi. All,
> Easy one for the experts.
> My country use a unique [13 number-digit] Identification system.
> The first 6-digits represent the date of birth [yymmdd]
> In my code the ID number is entered on a userform as text and
> displayed as follows 52-02-08-5034-087 [in this example the d.of b
> is 8-Feb-1952]
> Range("Bithday").Value = Left(Idnumber, 8)
> displays the required birthday in Range("Bithday")
> With the note "This cell contains a date string represented with
> only 2 digits for the year."
> If I select the option "Convert XX to 19XX" it gives me exactly
> what I want.
> I tried macro record but it doesn’t give me any result.
> How do I include the "Convert XX to 19XX" in my code ?
>
> --
> HJN


 
Reply With Quote
 
Hennie Neuhoff
Guest
Posts: n/a
 
      25th Aug 2009
Rick - Thank you very much - I think Joel did not read to question
--
HJN


"Rick Rothstein" wrote:

> You can let VB handle putting in the century for you using this code line...
>
> Range("Bithday").Value = CDate(Mid(IDnumber, 7, 3) & MonthName(Mid( _
> IDnumber, 4, 2)) & "-" & Left(IDnumber, 2))
>
> HOWEVER, the point at which VB switches from the 1900s to the 2000s is
> determined by the Windows' Regional Settings (which can be changed by the
> user). The default breakpoint is 1930... a 2-digit year before 30 will be in
> the 2000s (for example, 29 would become 2029 whereas a 2-digit year of 30 or
> later would be placed in the 1900 (for example, 30 would become 1930).
>
> --
> Rick (MVP - Excel)
>
>
> "Hennie Neuhoff" <(E-Mail Removed)> wrote in message
> news:065AAD99-D9DA-4EE4-A7D6-(E-Mail Removed)...
> > Hi. All,
> > Easy one for the experts.
> > My country use a unique [13 number-digit] Identification system.
> > The first 6-digits represent the date of birth [yymmdd]
> > In my code the ID number is entered on a userform as text and
> > displayed as follows 52-02-08-5034-087 [in this example the d.of b
> > is 8-Feb-1952]
> > Range("Bithday").Value = Left(Idnumber, 8)
> > displays the required birthday in Range("Bithday")
> > With the note "This cell contains a date string represented with
> > only 2 digits for the year."
> > If I select the option "Convert XX to 19XX" it gives me exactly
> > what I want.
> > I tried macro record but it doesn’t give me any result.
> > How do I include the "Convert XX to 19XX" in my code ?
> >
> > --
> > HJN

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically convert Text with 2-digit year =?Utf-8?B?anVuaXBlcjgxMA==?= Microsoft Excel Misc 2 16th Nov 2007 01:46 AM
Re: Addendum to 2 digit year to 4 digit year Ron Rosenfeld Microsoft Excel Misc 0 14th Dec 2006 05:48 PM
Re: Addendum to 2 digit year to 4 digit year David Biddulph Microsoft Excel Misc 0 14th Dec 2006 01:43 PM
Convert four digit year to two digits. =?Utf-8?B?YmQ4NTUyOA==?= Microsoft Access Queries 1 19th Jul 2005 04:41 PM
Convert Dates into four digit YEAR ONLY Richard Microsoft Excel Discussion 8 31st Jan 2005 08:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:33 AM.