Difference between revisions of "Date Functions"

(MakeDate(year, month, day))
(MakeDate(year, month, day))
Line 52: Line 52:
 
;Requirements: year, month, and date should be positive integers, or coercible to positive numbers.  
 
;Requirements: year, month, and date should be positive integers, or coercible to positive numbers.  
  
;[[Syntax:]] MakeDate(year: Coerce Positive; month, day: Optional Coerce Positive)
+
;[[Syntax]]: MakeDate(year: Coerce Positive; month, day: Optional Coerce Positive)
  
 
;Library: [[Special functions]]
 
;Library: [[Special functions]]

Revision as of 23:46, 2 February 2007

What's new in Analytica 4.0? >


Analytica 4.0 provides much greater flexibility for formatting dates -- in US and ROW (rest of the world) formats. It also adds four useful functions for computing with dates.

Date formats

You can control whether and how a number is displayed as a date in the Number Format dialog (available from the Result menu):

Number format.png

The date format in the Number Format dialog offers three standard date formats

  • short 8/26/2006
  • medium August-26-2006
  • long Thursday, 26 August, 2006

and a custom format. You can select an existing custom format or type in a new one.

  • d numerical day of the month, as 1, 2,... 31
  • dd numeric day of the month, as 01, 02,...31
  • www weekday in three letters, Mon, Tue,.. Sun
  • wwww weekday in full, as Monday, Tuesday, ... Sunday
  • M month as a number, 1, 2, ... 12
  • MM month as two-digit number, 01, 02, ...12
  • MMM month as three letter name, Jan, Feb, ... Dec
  • MMMM month as full name, January, February, ... December
  • yy year as two digits, 99, 00, 01
  • yyyy year as four digits, 1999, 2000, 2001

If you specify a date format for an input variable or Edit table, you can enter dates in any acceptable date format -- no matter which date format is specified. For example, with a date format, Analytica will interpret "9/11/2001" as "11 September, 2001" on a computer set to USA region or "9 November, 2001" elsewhere. With no date format, it will interpret it as ((9 divided by 11) divided by 2001)!

Date values and the date origin

Analytica represents a date as a date value -- that is, the number of days since the date origin. By default the date origin is Jan 1, 1904 -- as used by most Macintosh applications, including Excel on Macintosh, and all releases of Analytica on Macintosh and Windows up to Analytica 3.1. If you check Use Excel date origin in the Preferences... dialog, the date origin is Jan 1, 1900 -- as used in Excel on Windows (unless reset) and most other Windows software.

When using models using dates or date functions from Analytica releases 3.1 or earlier, you should keep Use Excel date origin unchecked. If you want to paste or link values from Excel for Windows or other Windows software to or from Analytica, you should check this option.

Analytica can handle dates from 1 AD to well beyond 9999 AD. Dates earlier than the date origin are represented as negative integers. Dates use the Gregorian calendar: Years divisible by 4 are leap years, except those divisible by 100 which are not leap years, except those divisible by 400 which are leap years.

You can simply add an integer n to a date to get the date n days ahead.

MakeDate(year, month, day)

Gives the date value for the date with that year, month, and day. If omitted, month and day default to 1.

Examples
MakeDate(2007,5,15) --> 15-May-2007
MakeDate(2000) --> 1-Jan-2000
Requirements
year, month, and date should be positive integers, or coercible to positive numbers.
Syntax
MakeDate(year: Coerce Positive; month, day: Optional Coerce Positive)
Library
Special functions

DatePart(date, part)

Gives the year, month, or day as a number, given a date value date. When part='Y', it gives the year as four digits, such as 2006. When part='M', it gives a number between 1 and 12. When part='D', it gives a number between 1 and 31.

Example
DatePart(MakeDate(2006, 2, 28), 'D') -> 28
Expects
date as a date number, and part as 'Y', 'M', or 'D'(upper- or lowercase).
Syntax: DatePart(date
Numeric; part: Text)
Library
Special functions

DateAdd(date, offset, unit)

Gives a date value that is offset years, months, or days from date, according to whether unit is "Y", "M", or "D".

Examples

DateAdd is especially useful for generating sequences of dates for a time index:

DateAdd(MakeDate(2006,1,1), 0..12, "M") 
-> ["1 Jan 2006", "1 Feb 2006", "1 Mar 2006", ... "1 Jan 2007"]

Returns the sequence

If an offset would appear to go past the end of a month, such as in:

DateAdd( MakeDate(2004, 2, 29), 1, 'Y' )  -> 2005-Feb-28
DateAdd( MakeDate(2006, 10, 31), 1, 'M' ) -> 2006-Nov-30

it returns the last day of the month. In the first example, the date 2005-Feb-29 does not exist, and in the second example the date 2006-Nov-31 doesn't exist, so in each case, the last day of the month is returned.

Adding a day offset, DateAdd(date, n,"D"), is equivalent to date+n, since date is represented as an integer.

Use a negative offset to subtract units from a date.

Expects
date and offset to be numbers, and part to be 'Y', 'M', or 'D' (upper or lowercase).
Syntax: DateAdd(date, offset
Number; unit: Text)
Library
Special functions
More examples and tips

Today()

Returns the date number for the day on which the function is evaluated. Unlike other functions, it gives a different value every day the model is run.

Library
Special functions
Comments


You are not allowed to post comments.