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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date/DateTime Type cannot be NEW()'ed with Date/DateTime instance

Quirks of Framework 2.0

Date/DateTime Type cannot be NEW()'ed with Date/DateTime instance

by  Qik3Coder  Posted    (Edited  )
Instead of:
Code:
[color blue]Dim[/color] myDate [color blue]As New[/color] Date(Now())
[color green]'or[/color]
[color blue]Dim[/color] myDateTime [color blue]As New[/color] DateTime(Now())
You must write:
Code:
[color blue]Dim[/color] myDate [color blue]As New[/color] Date()
myDate = Now()
[color green]'or[/color]
[color blue]Dim[/color] myDateTime [color blue]As New[/color] DateTime()
myDateTime = Now()

[color green]'OR[/color]

[color blue]Dim[/color] myDate [color blue]As Date[/color] = Now()
[color green]'or[/color]
[color blue]Dim[/color] myDateTime [color blue]As DateTime[/color] = Now()

Keep in mind this example may seem a little irrelevant, but it's a quirk of the system, you cannot create a new Date/DateTime instance with an instance of Date/DateTime.

Now you will probably say, "Well there are 11 different New constructors for the Date/Datetime Types. There must be one that you can use."

The problem lies in that only one of the constructors takes a base type (of Long), and the Date/DateTime types do not have a .ToLong property. All the other Constructors take date parts.

Thanks,

Qik3Coder
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top