I started bringing my app to API2 getting rid of decremented items.
Started at 18,205 warnings, now I’m at 11,962. All database stuff has been completed, next is date to datetime.
My programs tracks our membership for our society. As you can imagine Dates are used a lot.
I would like to know if anybody came across any gotch yas in converting to datetime.
Like I do this in a few place to get the last day of the month, would this work?:
Dim ldDateFrom As New Date( ldDate)
Dim ldDateTo as New Date( ldDate)
Dim ldToFilterDate as New Date
ldToFilterDate.Day = ldToFilterDate.Day + 1
ldDateFrom.Day = 1
ldDateTo.Month = ldDateTo.Month + 1
ldDateTo.Day = 1
ldDateTo.Day = ldDateTo.day - 1
Var ldDateFrom As DateTime
Var ldDateTo As DateTime
Var ldToFilterDate As DateTime
// Tomorrow
ldToFilterDate = DateTime.Now.AddInterval(0, 0, 1)
// First of this month at midnight
ldDateFrom = DateTime.Now.SubtractInterval(0, 0, DateTime.Now.Day - 1, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second)
// Last of this month at 23:59:59
ldDateTo = ldDateFrom.AddInterval(0, 1, -1, 23, 59, 59)
Most of you probably know this but for those that don’t, we replaced Date with DateTime because:
Users would often incorrectly modify dates and thus create errors in their apps.
Date was not designed to handle things like time zones and Daylight Savings Time which also lead to subtle errors.
DateTime makes it nearly impossible to get any of this wrong. Yes, it’s a bit more work sometimes but what ultimately matters is the reliability of one’s code, not the number of lines.
While it’s been alluded to, it’s important to note that Date.TotalSeconds and DateTime.SecondsSince1970 are not the same because TotalSeconds used a different base date.