Skip to main content
MindTouch Success Center

Date functions


The following functions and variables are part the DekiScript and MindTouch runtime environment.
 

date.adddays(datetime, days) : str

Add days to date-time.

Name Type Description
datetime str date time string
days num days to add

Determine the date 7 days before now and format it

var now = date.now;
var weekago = date.adddays(now,-7);
let weekago = date.format(weekago, "yyyy-MM-dd");
weekago;

date.addhours(datetime, hours) : str

Add hours to date-time.

Name Type Description
datetime str date time string
hours num hours to add

Determine the time 12 hours in the future and format it

var now = date.now;
var later = date.addHours(now,12);
let later = date.format(later, "HH:mm");
later;

date.addminutes(datetime, minutes) : str

Add minutes to date-time.

Name Type Description
datetime str date time string
minutes num minutes to add

date.addmonths(datetime, months) : str

Add months to date-time.

Name Type Description
datetime str date time string
months num months to add

date.addseconds(datetime, seconds) : str

Add seconds to date-time.

Name Type Description
datetime str date time string
seconds num seconds to add

date.addweeks(datetime, weeks) : str

Add weeks to date-time.

Name Type Description
datetime str date time string
weeks num weeks to add

date.addyears(datetime, years) : str

Add years to date-time.

Name Type Description
datetime str date time string
years num years to add

date.calendar(datetime, firstday) : list

Get list of calendar days for date-time month.

Name Type Description
datetime str date time string
firstday num (optional) first day of the week (one of 0 = Sunday, 1 = Monday, etc.; default: 0)

Loop over a list of days in the current month

var now = date.now;
<ul>
foreach (var month in date.calendar(now))
{
    foreach (var week in month)
    {
        // web.pre(week);         // Uncomment the web.pre function to see the week output
        <li>"The " .. week.dayofyear .. " day of the year is " .. week.dayname</li>
    }
}
</ul>

date.changetimezone(datetime, timezone) : str

Change time-zone of date-time.

Name Type Description
datetime str date time string
timezone str (optional) time-zone offset (format: ±hh:mm, default: GMT)

date.compare(first, second) : num

Compare the first date-time to the second date-time.

Name Type Description
first str first date time string
second str second date time string

date.date(datetime) : str

Show only date component of date-time.

Name Type Description
datetime str date time string

date.day(datetime) : str

Get day of month from date-time.

Name Type Description
datetime str date time string

date.dayname(datetime) : str

Get name of day from date-time.

Name Type Description
datetime str date time string

date.dayofweek(datetime) : num

Get day of the week from date-time.

Name Type Description
datetime str date time string

date.dayofyear(datetime) : num

Get day of the year from date-time.

Name Type Description
datetime str date time string

date.daysinmonth(datetime) : num

Get the number of days in date-time month.

Name Type Description
datetime str date time string

date.diffdays(first, second) : num

Compute the difference between the first and second date-time in days.

Name Type Description
first str first date time string
second str second date time string

date.diffhours(first, second) : num

Compute the difference between the first and second date-time in hours.

Name Type Description
first str first date time string
second str second date time string

date.diffminutes(first, second) : num

Compute the difference between the first and second date-time in minutes.

Name Type Description
first str first date time string
second str second date time string

date.diffmonths(first, second) : num

Compute the difference between the first and second date-time in months.

Name Type Description
first str first date time string
second str second date time string

date.diffseconds(first, second) : num

Compute the difference between the first and second date-time in seconds.

Name Type Description
first str first date time string
second str second date time string

date.format(datetime, format) : str

Show date-time in custom format.

Name Type Description
datetime str date time string
format str date time format string (one of "iso-d", "iso-Www", "iso-yyyy", "iso-Www-d", "iso-yyyy-Www", "iso-yyyy-Www-d", or custom formatting string: see http://msdn2.microsoft.com/EN-US/lib.../az4se3k1.aspx)

Output Different Date Formats - Custom Format Strings

date.format(date.now,"MMMM dd, yyyy");          //  July 10, 2014
date.format(date.now,"dddd MMMM dd, yyyy");     //  Monday July 10, 2014

date.hours(datetime) : num

Get the hours component of date-time.

Name Type Description
datetime str date time string

date.inrange(datetime, lower, upper, dateonly) : bool

Check if date-time occurs between lower and upper date-time, inclusive.

Name Type Description
datetime str date time to check
lower str lower bound for date time
upper str upper bound for date time
dateonly bool (optional) check if the date-time falls within the date range, ignoring time-of-day

date.isafter(first, second) : bool

Check if first date-time is after second date-time.

Name Type Description
first str first date time string
second str second date time string

date.isbefore(first, second) : bool

Check if first date-time is before second date-time.

Name Type Description
first str first date time string
second str second date time string

date.isoweek(datetime) : map

Convert date-time into ISO 8601 week-date values. (http://en.wikipedia.org/wiki/ISO_8601)

Name Type Description
datetime str date time string

date.issameday(first, second) : bool

Check if first date-time and the second date-time fall on the same day.

Name Type Description
first str first date time string
second str second date time string

date.issamemonth(first, second) : bool

Check if first date-time and the second date-time fall on the same month.

Name Type Description
first str first date time string
second str second date time string

date.issameweek(first, second) : bool

Check if first date-time and the second date-time fall on the same week.

Name Type Description
first str first date time string
second str second date time string

date.isvalid(datetime) : bool

Check if the string is a valid date-time.

Name Type Description
datetime str (optional) date time string

date.max(first, second) : str

Compare the first date-time to the second date-time and return the later one.

Name Type Description
first str first date time string
second str second date time string

date.min(first, second) : str

Compare the first date-time to the second date-time and return the earlier one.

Name Type Description
first str first date time string
second str second date time string

date.minutes(datetime) : num

Get the minutes component of date-time.

Name Type Description
datetime str date time string

date.month(datetime) : str

Get 2-digit month from date-time.

Name Type Description
datetime str date time string

date.monthname(datetime) : str

Get name of the month from date-time.

Name Type Description
datetime str date time string

date.new(year, month, day, hour, minute, second, timezone) : str

Create new date-time value.

Name Type Description
year num Year value
month num Month value (1-12)
day num Day value (1-31)
hour num (optional) Hour value (0-23, default: 0)
minute num (optional) Minute value (0-59, default: 0)
second num (optional) Second value (0-59, default: 0)
timezone str (optional) time-zone offset (format: ±hh:mm, default: GMT)

date.now : str

Current date-time in GMT format.

date.now;  // Parenthesis should not be used

date.parse(text, format, culture, timezone) : str

Parse a custom date-time string.

Name Type Description
text str text to parse
format str (optional) custom date formatting string: see http://msdn2.microsoft.com/EN-US/lib.../az4se3k1.aspx (default: best effort parsing)
culture str (optional) culture code (default: page or site culture)
timezone str (optional) timezone offset to use, if none given in the date (format: ±hh:mm, default: GMT)

date.parseisoweek(isoweekdate) : str

Parse an ISO 8601 week-date string. (http://en.wikipedia.org/wiki/ISO_8601)

Name Type Description
isoweekdate str full ISO 8601 week string (e.g. "yyyy-Www-d")

date.parts(datetime) : map

Decompose a date-time into its components parts.

Name Type Description
datetime str date time string

date.seconds(datetime) : num

Get the seconds component of date-time.

Name Type Description
datetime str date time string

date.startofday(datetime) : str

Get date-time corresponding to beginning of day (i.e. midnight).

Name Type Description
datetime str date time string

date.startofmonth(datetime) : str

Get date-time corresponding to beginning of month.

Name Type Description
datetime str date time string

date.startofweek(datetime) : str

Get date-time corresponding to beginning of week (i.e. Sunday).

Name Type Description
datetime str date time string

date.startofyear(datetime) : str

Get date-time corresponding to beginning of year.

Name Type Description
datetime str date time string

date.time(datetime) : str

Get time from date-time.

Name Type Description
datetime str date time string

date.timezone(datetime, default) : str

Get the time-zone component of date-time.

Name Type Description
datetime str date time string
default str (optional) default timezone (default: GMT)

date.timezonenow(timezone) : str

Current date-time in time-zone format.

Name Type Description
timezone str (optional) time-zone offset (format: ±hh:mm, default: GMT)

date.timezonetoday(timezone) : str

Beginning of day for GMT timezone.

Name Type Description
timezone str (optional) time-zone offset (format: ±hh:mm, default: GMT)

date.today() : str

Beginning of day for GMT timezone.

date.week(datetime) : num

Get week of year from date-time.

Name Type Description
datetime str date time string

date.year(datetime) : str

Get 4-digit year from date-time.

Name Type Description
datetime str date time string
  • Was this article helpful?