Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,561 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,888 people online right now. Registration is fast and FREE... Join Now!




automatic display of year

 
Reply to this topicStart new topic

automatic display of year

emkaye
12 May, 2008 - 08:56 PM
Post #1

D.I.C Head
**

Joined: 12 Aug, 2007
Posts: 54


My Contributions
i have a label that would automatically display its code. Its code is in this kind of format:

0801

where:

08 indicates the year (2008) and 01 indicates the month (01 if january, 02 if february, 03 if march, and so on and so forth)...

what i wanted to display is only the last two digits of the year 2008 which is 08. But it is not working. Please help. Below is my code:

CODE


Dim NewNo as String
NewNo = Trim(2-Len (Str((Year(Date)))))
lblYear = NewNo



Thanks in advance!

User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Automatic Display Of Year
12 May, 2008 - 09:42 PM
Post #2

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
CODE

lblDate.Caption = Right(Year(Date), 2)
    If Month(Date) < 10 Then
        lblDate.Caption = lblDate.Caption & "0" & Month(Date)
    Else
        lblDate.Caption  = lblDate.Caption & Month(Date)
    End If


I'm first using Year(Date) to get the year, "2008". I have the Right function wrapped around it though, so it's only taking the last two numbers from the year. Next I determine if the month is less than 10, and if so, I make it display a zero before the month, so that instead of it saying "085", it'll say "0805".

This post has been edited by Zhalix: 12 May, 2008 - 10:19 PM
User is offlineProfile CardPM
+Quote Post

anand_the_great
RE: Automatic Display Of Year
12 May, 2008 - 10:42 PM
Post #3

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 34

Hello Emkaye are you Philipines. Wow great, there are a lot of beautiful girls there. =).
However, like what I always preach, "lesser the coding ,lesser the complexity".
Try this ok. Best to put this of line in Form_Load() ok.
CODE

Label1 = Format(Now(), "yymm")


Format = is function to format any string like currency and stuff.
Put the variables in the Format(input_here, "your output style here")
Now() = will display the current date and time in full.
So you can choose display what you want the lonf string.
Say, you want the date as 080501 ----> Format(Now(), "yymmdd")
year year month month day day
Have fun.
Anand.

This post has been edited by anand_the_great: 12 May, 2008 - 10:46 PM
User is offlineProfile CardPM
+Quote Post

Zhalix
RE: Automatic Display Of Year
12 May, 2008 - 10:45 PM
Post #4

D.I.C Head
**

Joined: 7 May, 2008
Posts: 218



Thanked: 9 times
My Contributions
Wow, I had no idea. You learn somethin' new every day. tongue.gif
User is offlineProfile CardPM
+Quote Post

sam_benne
RE: Automatic Display Of Year
12 May, 2008 - 10:45 PM
Post #5

D.I.C Regular
Group Icon

Joined: 16 Jan, 2008
Posts: 298



Thanked: 1 times
Dream Kudos: 400
My Contributions
This can work to Mid strings. These are great because they can pick what you need out so:
CODE

Year = Mid(Year, 3, 2)

Wolud be 2008 = 08.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:36PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month