TIP: Careful of the order you assign items to Date

A tip to help other’s bypass my mistake. Be careful of the order you assign .day to a date.

If you do this:

Dim d as new date d.day = day d.month = month d.year = year

It may occasionally fail. For instance, this fails

[code]// It’s currently Feb
Dim d as new date
// Date = Feb 17, 2014

d.day = 30
// Date = Feb 30, 2014. Which doesn’t exist. So it becomes March 2, 2014

d.month = 1
// Date is now Jan 2, 2014 instead of Jan 30.[/code]

Do this instead:

Dim d as new date d.year = year d.month = month d.day = day

Or even better, use the Date constructor like this:

dim d as new Date(2014, 2, 17)

Quite right!