Actually I was thinking a bit about adding time-spans to a date on the bus home. Adding seconds, minutes, days and even weeks is OK because they are a constant length, however if I want to add a year to a date (as distinct from 365 days), that isn't going to work with day numbers when leap years are involved. J's 6-item lists actually work well in either case:
StartDate=: 2008 1 31 14 12 7.2 NB. Adding 365 days is easy with day numbers: toDateTime 365 + toDayNumber StartDate 2009 1 30 14 12 7.2 NB. Can do it with J timestamp format too: toDateTime toDayNumber 0 0 365 0 0 0 + StartDate 2009 1 30 14 12 7.2 NB. With J timestamp format you also simply add 1 year: toDateTime toDayNumber 1 0 0 0 0 0 + StartDate 2009 1 31 14 12 7.2 NB. or 2 months: toDateTime toDayNumber 0 2 0 0 0 0 + StartDate 2008 3 31 14 12 7.2 Those last two are significantly more difficult to accomplish using day numbers, because you need to know which years/months you are working with because that will determine their time-span. Of course it depends what you're trying to accomplish! Ideally toDateTime and toDayNumber should be extended to handle fractional days eg: toDateTime toDayNumber 0 0 365.25 0 0 0 + StartDate Currently the YMD portion is handed off to todayno which "ignores" them so they aren't taken into account. Ric Example definitions for toDateTime and toDayNumber can be found here: "http://www.jsoftware.com/jwiki/RicSherlock/Extend%20Dates%20Project/DatesAdd%20Script" > From: Alex Rufon > > To support this concept of date and time, I actually made the following > verbs: > NB. ========================================================= > NB.*dateplus (a) Adds day and fractional time to a date > NB. > NB. x is calendar date > NB. y is day and fractional time > NB. returns calendar date in YYYYMMDD.fractional time > > NB. ========================================================= > NB.*dateminus (a) Subtracts a day and fractional time to a date > NB. > NB. x is calendar date > NB. y is day and fractional time > NB. returns calendar date in YYYYMMDD.fractional time > > NB. ========================================================= > NB.*dateminusdate (a) Subtracts two dates and returns days and > fractional time > NB. > NB. x is calendar date > NB. y is calendar date > NB. returns days and fractional time > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
