Cannot get the current year using vbDate or vbLongDate

0 pts.
Tags:
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.
ASKED: November 10, 2005  3:30 AM
UPDATED: November 10, 2005  11:23 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Gerhemmes
    solved thank you, jswalwell !
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following