Date type

In AskiaScript, a date variable contains date and/or time information.

In this topic:

Creating a date type variable

Date

Assign a date to a variable with the date between hash characters (#), and using the slash character (/) as separator. The format is:

#DD/MM/YYYY#

For example:

dim my_date = #25/03/2011#

Time

Assign a time to a variable with the time between hash characters (#), and using the colon character (:) as separator. The format is:

#HH:MM[:SS]#

Note: the seconds are optional.

For example:
dim my_time = #16:32#
dim my_time = #16:32:07#

Date and time together

Assign a date and time to a variable, with the date and time between hash characters (#). Use the slash character (/) as a separator for the date and the colon character (:) as a separator for the time. The date and time should be separated from each other by a space. The format is:

#DD/MM/YYYY HH:MM[:SS]#

For example:

dim my_date = #25/03/2011 16:32#
dim my_date = #25/03/2011 16:32:07#

↑ Top of page ↑

Properties

Day

Returns the day from the specified date, as a number.

Returns a Number.

Example
dim dt = #25/03/2011#
dt.Day ' => 25

↑ Top of page ↑

Month

Returns the month from the specified date, as a number.

Returns a Number.

Example
dim dt = #25/03/2011#
dt.Month ' => 3

↑ Top of page ↑

Year

Returns the year from the specified date, as a number.

Returns a Number.

Example
dim dt = #25/03/2011#
dt.Year ' => 2011

↑ Top of page ↑

Hour

Returns the hour from the specified time, as a number.

Returns a Number.

Example
dim tm = #16:32:07#
tm.Hour ' => 16

↑ Top of page ↑

Minute

Returns the minute from the specified time, as a number.

Returns a Number.

Example
dim tm = #16:32:07#
tm.Minute ' => 32

↑ Top of page ↑

Second

Returns the second from the specified time, as a number.

Returns a Number.

Example
dim tm = #16:32:07#
tm.Second ' => 7

↑ Top of page ↑

DayOfWeek

Returns the day of the week (1-7) from the specified date, as a number, where Sunday is day 1:

Returns a Number.

Example
dim dt = #25/03/2011#
dt.DayOfWeek ' => 6

↑ Top of page ↑

DayOfYear

Returns the day of the year (1-366) from the specified date, as a number:

Returns a Number.

Example
dim dt = #25/03/2011#
dt.DayOfYear ' => 84

↑ Top of page ↑

Methods

ToNumber()

Converts the specified date to a number.

Returns a Number.

Example
dim dt= #25/03/2011 16:32:07#
dt.ToNumber() ' => 40627.688969907409

↑ Top of page ↑

Format(format)

Formats the specified date to a string, using the specified format parameter.

Returns a String.

Parameters
Warning: The format parameter is case sensitive.

 

See Date Formatting

Examples
dim dt= #02/03/2011 16:32:07# ' March 2nd, 2011
dt.Format("dd/MM/yyyy") ' => "02/03/2011"
dim dt= #02/03/2011 16:32:07# ' March 2nd, 2011
dt.Format("yyyy-MM-dd") ' => "2011-03-02"
dim dt= #02/03/2011 16:32:07# ' March 2nd, 2011
dt.Format("MM/dd/yyyy") ' => "03/02/2011"
dim dt= #02/03/2011 16:32:07# ' March 2nd, 2011
dt.Format("dd MMM yyyy") ' => "02 Mar 2011"
dim dt= #02/03/2011 16:32:07# ' March 2nd, 2011
dt.Format("dd MMMM yyyy") ' => "02 March 2011"
dim dt= #02/03/2011 16:32:07# ' March 2nd, 2011
dt.Format("MMMM dd, ddd.  yyyy") ' => "March 02, Wed. 2011"
dim dt= #02/03/2011 16:32:07# ' March 2nd, 2011
dt.Format("MMMM dd, dddd yyyy") ' => "March 02, Wednesday 2011"
dim dt= #02/03/2011 16:32:07# ' March 2nd, 2011
dt.Format("d-M-yy") ' => "2-3-11"
dim dt= #02/03/2011 16:32:07# ' March 2nd, 2011
dt.Format("dd/MM/yyyy HH:mm") ' => "02/03/2011 16:32"
dim dt= #02/03/2011 16:32:07# ' March 2nd, 2011
dt.Format("dd/MM/yyyy hh:mm") ' => "02/03/2011 04:32"
dim dt= #02/03/2011 16:32:07# ' March 2nd, 2011
dt.Format("dd/MM/yyyy hh:mmampm") ' => "02/03/2011 04:32pm"
dim dt= #02/03/2011 16:32:07# ' March 2nd, 2011
dt.Format("dd/MM/yyyy hh:mm:ssAMPM") ' => "02/03/2011 04:32:07PM"

↑ Top of page ↑

ToString()

Converts a date to a string using the regional settings context (using either the language of the respondent, or the current machine).

Returns a String.

If you wish to enforce the date format, use the Format method.
Example

dim dt= #25/03/2011 16:32:07#
dt.ToString() ' => "25/03/2011 16:32:07" or "3/25/2011 04:32:07 PM"
' depending on the regional settings

↑ Top of page ↑

TypeOf()

Always returns "date".

Returns a String.

Example
dim dt= #12/01/2009#
dt.TypeOf() ' => "date"

↑ Top of page ↑

Operators

Warning:
Date * X = Not allowed
Date / X = ""

 

Name Symbol / Expression Description Example
Addition +

Addition.

Returns a date.

dim i = #25/03/2011 16:32:07#
i + 3 ' => #28/03/2011 16:32:07#
i + (3/24) ' => #25/03/2011 19:32:07#
i + (3/(24*60)) ' => #25/03/2011 16:35:07#
i + (3/(24*60*60)) ' => #25/03/2011 16:32:10#
Attention: 
Date + Date = Error
Subtraction -

Subtraction.

Returns a date or a number.

dim i = #25/03/2011 16:32:07#
dim j = #23/05/2010 11:05:58#
i - 3 ' => #22/03/2011 16:32:07#
i - (3/24) ' => #25/03/2011 13:32:07#
i - (3/(24*60)) ' => #25/03/2011 16:29:07#
i - (3/(24*60*60)) ' => #25/03/2011 16:32:04#
i - j ' => 306.2264930555539
j - i ' => -306.2264930555539
Attention:
Date - Number = Date
Date - Date = Number
Equal =

Tests whether two dates are equal.

Returns a boolean.

To use this operator for comparisons, the condition should be between brackets, or else it will be considered an assignment operator.
dim i = #25/03/2011#
(i = #24/03/2011#) ' => False
(i = #25/03/2011#) ' => True
Different <>

Tests whether two dates are not equal.

Returns a boolean.

dim i = #25/03/2011#
i <> #24/03/2011# ' => True
i <> #25/03/2011# ' => False
Less than <

Tests the relative sizes between two dates.

Returns a boolean.

dim i = #25/03/2011#
i < #24/03/2011# ' => False
i < #25/03/2011# ' => False
i < #26/03/2011# ' => True
Less or equal than <=

Tests the relative sizes between two dates.

Returns a boolean.

dim i = #25/03/2011#
i <= #24/03/2011# ' => False
i <= #25/03/2011# ' => True
i <= #26/03/2011# ' => True
Greater than >

Tests the relative sizes between dates.

Returns a boolean.

dim i = #25/03/2011#
i > #24/03/2011# ' => True
i > #25/03/2011# ' => False
i > #26/03/2011# ' => False
Greater or equal than >=

Tests the relative sizes between two dates.

Returns a boolean.

dim i = #25/03/2011#
i >= #24/03/2011# ' => True
i >= #25/03/2011# ' => True
i >= #26/03/2011# ' => False

↑ Top of page ↑

Date Formatting

Warning: The date formatting string is case sensitive.

 

String Description
yy Year without the century (00 - 99).
yyyy Year with the century, for example 2000.
M Month number, without a leading zero (1 - 12).
MM Month number, with a leading zero when the number would otherwise have only one digit (01 - 12).
MMM The name of the month as an abbreviation (Jan - Dec).
MMMM The name of month in full (January - December).
d Day of the month, without a leading zero (1 - 31).
dd Day of the month, with a leading zero when the number would otherwise have only one digit (01 - 31).
ddd Name of the day of the week as an abbreviation (Sun - Sat).
dddd Name of the day of the week (Sunday - Saturday).
h Hour, in 12-hour format, without a leading zero (0 - 12).
hh Hour, in 12-hour format, with a leading zero when the hour would otherwise have only one digit (00 - 12).
H Hour, in 24-hour format, without a leading zero (0 - 23).
HH Hour, in 24-hour format, with a leading zero when the hour would otherwise have only one digit (00 - 23).
m Minutes, without a leading zero (0 - 59).
mm Minutes, with a leading zero when the minutes would otherwise have only one digit (00 - 59).
s Seconds, without a leading zero (0 - 59).
ss Seconds, with a leading zero when the seconds would otherwise have only one digit (00 - 59).
ampm Display the "am" string literal with any hour before noon and display the "pm" string literal with any hour between noon and 23:59.
AMPM Display the "AM" string literal with any hour before noon and display the "PM" string literal with any hour between noon and 23:59.
[All other characters] Literal character; displayed as typed.

 

↑ Top of page ↑

Create your own Knowledge Base