Question

Asked:
Asked By:
Nov 10 2005   3:30 AM GMT
gerhemmes   0 pts.

Cannot get the current year using vbDate or vbLongDate


VBA

I have tried to get the current year (2005), with the following statements:
helpfield = DatePart("yyyy", vbLongDate)
helpfield = DatePart("yyyy", vbDate)

The first statement gives me the year 1899; in debugging I can see that vbLongDate = 1.
The second statement gives me the year 1900; in debugging I can see that vbDate = 7.

I am running Windows XP Professional, Microsoft Access 2002 (SP3), Microsoft Visual Basic 6.3.

Thanks for any help.

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



vbLongDate and vbDate are actually constants that will always return the same value: 1 and 7 respectively. vbLongDate is a formatting constant and vbDate is the value representing a date object.

To get the current date and time in VB use the function Now() as follows: helpfield = DatePart("yyyy", Now())

This will correctly return 2005.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Development.

Looking for relevant Development Whitepapers? Visit the SearchWinDevelopment.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

gerhemmes   0 pts.  |   Nov 10 2005  11:23AM GMT

solved

thank you, jswalwell !

 

vb6 get current year   0 pts.  |   Jul 11 2008  2:58PM GMT

[...] [...]