Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET 4 Vis WEB Dev 2010 How do I build a date? the dateserial function no longer works

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
Dim Today As Date
Today = DateSerial(Year(Now), Month(Now), Day(Now))

Day has a red line under it?
intellisense note "Day is a type and cannot be used as an expression" ???


DougP
 
I am not sure why you would do that...If you want a date object with the current date in it, you should be able to use (note: I am not using Today as my variable name as this creates unclear code in my opinion because of reserverd/system keywords in various code languages):

Dim CurrentDate As Date = DateTime.Today
or
Dim CurrentDate As Date = DateTime.Now '(with current time included)

If you want to build the date with a DateSerial, I recommend you use something like:

Dim CurrentDate As Date = DateSerial(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day)

This format is more in line with best practices and .Net framework usage.

See for more details.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
C#.NET Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top