Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Comparing Date-typed Variables

How do I compare dates in VB? Also, how do I store dates into Access? I can't get them into the right format.

For comparison of dates, look up the documentation on the DateDiff function. There are several other similar functions for adding dates and getting pieces of the date. DateDiff is a very powerful and useful function.

As far as storing dates, Access is fairly forgiving about how dates look. If you are doing insert statements into the database, put the date into a Variant type before you do it as Access likes that better. You can use the CVar function to convert just about anything to a variant, but don't use Variant variables as each one takes 64k of memory. Not good. If you set the format property on the masked edit box, you can get the date in the format you want fairly easily.

To format dates, use the Format function. The Format function allows you to format a date in virtually any format imaginable, including generic International dates.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date