Date Functions

Date functions perform various operations on date and time values, including extracting individual components (day, month, year, hour, minute, second), calculating age or duration, retrieving the current date and time, and formatting dates for display.

Accepted Date Parameters

Date functions accept date values in several formats:

Format

Description

Example

Date literal

Date enclosed in hash symbols

#27/06/2006# or #27/06/06#

String date

Date as a string with delimiters (/, \, -, .)

"27/06/2006" or "27-06-2006"

String with time

Date and time as a string

"02/07/2006 12:57:20"

Data field

Field reference containing a date

|->[DOB]

Expression

Any QLingo expression returning a date

AsDate(|->[DateText])

Note: The format of the date value is locale specific. XMPie products will use your computer's regional date settings to determine how date values are represented on your system. day/month/year or month/day/year The code examples and results displayed on this page are in the day/month/year format.

GetDay function

The GetDay function extracts the day of the month from a date expression, returning a value from 1 to 31.

This function returns a Number data type.

Syntax

GetDay(dateExpression)

Parameter

Description

dateExpression

Required. A date value from which to extract the day.

Examples

  1. Get the day from a date literal:

    GetDay(#01/02/2025#)

    Result: 1

  2. Get the day from a date string with time:

    GetDay("02/07/2006 12:57:20")

    Result: 2

  3. Get the day from a recipient's date field:

    GetDay(|->[OrderDate])

    If OrderDate = #15/03/2024#:

    Result: 15

  4. Create a formatted date string using components:

    "Day " & AsString(GetDay(|->[EventDate])) & " of the month"

    If EventDate = #22/11/2024#:

    Result: "Day 22 of the month"

GetMonth function

The GetMonth function extracts the month from a date expression, returning a value from 1 (January) to 12 (December).

This function returns a Number data type.

Syntax

GetMonth(dateExpression)

Parameter

Description

dateExpression

Required. A date value from which to extract the month.

Examples

  1. Get the month from a date literal:

    GetMonth(#01/02/2025#)

    Result: 2 (February)

  2. Get the month from a date string with time:

    GetMonth("02/07/2006 12:57:20")

    Result: 7 (July)

  3. Determine the quarter based on month:

    Switch (Ceil(GetMonth(|->[SaleDate]) / 3))
    {
    case 1:
    "Q1"
    case 2:
    "Q2"
    case 3:
    "Q3"
    case 4:
    "Q4"
    }

    If SaleDate = #15/08/2024# (August):

    Result: "Q3"

  4. Check if a date falls in a specific month:

    If (GetMonth(|->[BirthDate]) = GetMonth(Now()))
    {
    "Happy Birthday Month!"
    }
    else
    {
    ""
    }

GetYear function

The GetYear function extracts the four-digit year from a date expression.

This function returns a Number data type.

Syntax

GetYear(dateExpression)

Parameter

Description

dateExpression

Required. A date value from which to extract the year.

Examples

  1. Get the year from a date literal:

    GetYear(#01/02/2025#)

    Result: 2025

  2. Get the year from a date string with time:

    GetYear("02/07/2006 12:57:20")

    Result: 2006

  3. Calculate years since a specific date:

    GetYear(Now()) - GetYear(|->[JoinDate])

    If JoinDate = #15/03/2019# and current date is #13/06/2025#:

    Result: 6

  4. Create a copyright notice with current year:

    "Copyright " & AsString(GetYear(Now())) & " Acme Corp."

    Result: "Copyright 2025 Acme Corp."

  5. Check if an event is in the current year:

    If (GetYear(|->[EventDate]) = GetYear(Now()))
    {
    "This Year"
    }
    else
    {
    "Other Year"
    }

GetDayOfWeek function

The GetDayOfWeek function returns the day of the week for a date expression as a number from 1 to 7, where 1 represents Sunday and 7 represents Saturday.

This function returns a Number data type.

Syntax

GetDayOfWeek(dateExpression)

Parameter

Description

dateExpression

Required. A date value from which to determine the day of the week.

Day of Week Values

Value

Day

1

Sunday

2

Monday

3

Tuesday

4

Wednesday

5

Thursday

6

Friday

7

Saturday

Examples

  1. Get the day of week from a date literal:

    GetDayOfWeek(#01/02/2025#)

    Result: 7 (Saturday)

  2. Convert the day of week number to a name:

    Switch(GetDayOfWeek(|->[AppointmentDate])
    {
    case 1: "Sunday"
    case 2: "Monday"
    case 3: "Tuesday"
    case 4: "Wednesday"
    case 5: "Thursday"
    case 6: "Friday"
    case 7: "Saturday"
    }

  3. Check if a date falls on a weekend:

    If (GetDayOfWeek(|->[DeliveryDate]) = 1 Or GetDayOfWeek(|->[DeliveryDate]) = 7)
    {
    "Weekend Delivery"
    }
    else
    {
    "Weekday Delivery"
    }

  4. Determine if today is a weekday:

    If (GetDayOfWeek(Now()) >= 2 And GetDayOfWeek(Now()) <= 6)
    {
    "Business Day"
    }
    else
    {
    "Weekend"
    }

GetHour function

The GetHour function extracts the hour from a date/time expression, returning a value from 0 to 23 (24-hour format). If the date expression does not include a time component, the function returns 0 (midnight).

This function returns a Number data type.

Syntax

GetHour(dateExpression)

Parameter

Description

dateExpression

Required. A date/time value from which to extract the hour.

Examples

  1. Get the hour from a date without time (defaults to midnight):

    GetHour(#01/02/2025#)

    Result: 0

  2. Get the hour from a date/time string:

    GetHour("02/07/2006 12:57:20")

    Result: 12

  3. Determine the time of day:

    If (GetHour(|->[LoginTime]) < 12)
    {
    "Morning"
    }
    else If (GetHour(|->[LoginTime]) < 17)
    {
    "Afternoon"
    }
    else
    {
    "Evening"
    }

  4. Get the current hour:

    GetHour(Now())

    If current time is 3:45 PM:

    Result: 15

GetMinute function

The GetMinute function extracts the minute from a date/time expression, returning a value from 0 to 59. If the date expression does not include a time component, the function returns 0.

This function returns a Number data type.

Syntax

GetMinute(dateExpression)

Parameter

Description

dateExpression

Required. A date/time value from which to extract the minute.

Examples

  1. Get the minute from a date without time (defaults to 0):

    GetMinute(#01/02/2025#)

    Result: 0

  2. Get the minute from a date/time string:

    GetMinute("02/07/2006 12:57:20")

    Result: 57

GetSecond function

The GetSecond function extracts the second from a date/time expression, returning a value from 0 to 59. If the date expression does not include a time component, the function returns 0.

This function returns a Number data type.

Syntax

GetSecond(dateExpression)

Parameter

Description

dateExpression

Required. A date/time value from which to extract the second.

Examples

  1. Get the second from a date without time (defaults to 0):

    GetSecond(#01/02/2025#)

    Result: 0

  2. Get the second from a date/time string:

    GetSecond("02/07/2006 12:57:20")

    Result: 20

Age function

The Age function calculates the number of years between a date expression and the current date/time. The result is returned as a decimal number representing the precise age in years. While commonly used for calculating a person's age from their birth date, this function works with any date.

This function returns a Number data type (decimal).

Syntax

Age(dateExpression)

Parameter

Description

dateExpression

Required. A date value representing the starting date for the age calculation.

Examples

  1. Calculate age from a date string:

    Age("31/01/1973")

    Result: 52.8164383561644 (as of late 2025)

  2. Calculate whole years of age (most common use):

    Floor(Age(|->[DOB]))

    If DOB = #15/06/1985# and current date is November 2025:

    Result: 40

  3. Calculate age from a text field converted to a date:

    Floor(Age(AsDate(|->[BirthDateText])))

    If BirthDateText = "03/22/1990":

    Result: 35 (depending on current date)

  4. Determine age group for marketing:

    If (Floor(Age(|->[DOB])) < 25)
    {
    "Young Adult"
    }
    else If (Floor(Age(|->[DOB])) < 45)
    {
    "Adult"
    }
    else If (Floor(Age(|->[DOB])) < 65)
    {
    "Middle Age"
    }
    else
    {
    "Senior"
    }

  5. Calculate years since an event (e.g., customer anniversary):

    Floor(Age(|->[FirstPurchaseDate]))

    If FirstPurchaseDate = #10/05/2020# and current date is November 2025:

    Result: 5

  6. Check if someone is at least 18 years old:

    If (Age(|->[DOB]) >= 18)
    {
    "Eligible"
    }
    else
    {
    "Not Eligible"
    }

Tip: Use Floor(Age(...)) to get whole years, which is typically what you want for displaying a person's age or calculating anniversaries.

Now function

The Now function returns the current system date and time at the moment of composition. This is useful for timestamps, calculating deadlines, or personalizing content based on the current date.

This function returns a Date data type.

Syntax

Now()

This function takes no parameters.

Examples

  1. Get the current date and time:

    Now()

    Result: Current date and time (e.g., #25/11/2025 14:30:00#)

  2. Format the current date:

    FormatDate(Now(), "dd/MM/yyyy")

    Result: "25/11/2025" (current date formatted)

  3. Calculate a date 30 days in the future:

    Now() + 30

    Result: Date 30 days from now

  4. Create an expiration date message:

    "This offer expires on " & FormatDate(Now() + 14, "MMMM d, yyyy")

    Result: "This offer expires on December 9, 2025"

  5. Add a timestamp to generated content:

    "Generated: " & FormatDate(Now(), "MM/dd/yyyy HH:mm:ss")

    Result: "Generated: 11/25/2025 14:30:45"

  6. Calculate days until an event:

    AsNumber(|->[EventDate]) - AsNumber(Now())

    Result: Returns the number of days until the event date.

  7. Personalize greeting based on time of day:

    If (GetHour(Now()) < 12)
    {
    "Good morning"
    }
    else If (GetHour(Now()) < 17)
    {
    "Good afternoon"
    }
    else
    {
    "Good evening"
    }

Note: The Now() function returns the date and time at the moment the job is composed. For batch jobs, all recipients in the same job will have the same Now() value.

FormatDate function

The FormatDate function converts a date to a formatted string according to a specified pattern. This provides complete control over how dates are displayed, including support for different date formats, localized month and day names, and various time formats.

This function returns a String data type.

Syntax

FormatDate(dateExpression, formatString)

Parameter

Description

dateExpression

Required. The date value to format.

formatString

Required. A pattern string that defines the output format using format specifiers.

Format Specifiers

Day Specifiers

Specifier

Description

Example

d

Day of month without leading zero

1, 15, 31

dd

Day of month with leading zero

01, 15, 31

ddd

Abbreviated day name

Mon, Tue, Wed

dddd

Full day name

Monday, Tuesday, Wednesday

Month Specifiers

Specifier

Description

Example

M

Month without leading zero

1, 6, 12

MM

Month with leading zero

01, 06, 12

MMM

Abbreviated month name

Jan, Jun, Dec

MMMM

Full month name

January, June, December

Year Specifiers

Specifier

Description

Example

y

Year without century (1 digit if possible)

5, 25

yy

Year without century (2 digits)

05, 25

yyy

Year with minimum 3 digits

025, 2025

yyyy

Four-digit year

2025

Time Specifiers

Specifier

Description

Example

h

Hour (12-hour) without leading zero

1, 12

hh

Hour (12-hour) with leading zero

01, 12

H

Hour (24-hour) without leading zero

0, 13, 23

HH

Hour (24-hour) with leading zero

00, 13, 23

m

Minute without leading zero

0, 30, 59

mm

Minute with leading zero

00, 30, 59

s

Second without leading zero

0, 30, 59

ss

Second with leading zero

00, 30, 59

AM/PM Specifiers

Specifier

Description

Example

t

Single character AM/PM (uppercase)

A, P

tt

Full AM/PM (uppercase)

AM, PM

T

Single character AM/PM (uppercase)

A, P

TT

Full AM/PM (uppercase)

AM, PM

Examples

  1. Format a date with full day and month names:

    FormatDate(#27/06/2006#, "dddd, MMMM dd, yyyy")

    Result: "Tuesday, June 27, 2006"

  2. Format a date in abbreviated style:

    FormatDate(|->[DOB], "ddd MMM d")

    If DOB = #15/03/1985#:

    Result: "Fri Mar 15"

  3. Format with numeric date (US style):

    FormatDate(|->[OrderDate], "MM/dd/yyyy")

    If OrderDate = #25/12/2025#:

    Result: "12/25/2025"

  4. Format with numeric date (European style):

    FormatDate(|->[OrderDate], "dd/MM/yyyy")

    If OrderDate = #25/12/2025#:

    Result: "25/12/2025"

  5. Format with ISO 8601 style:

    FormatDate(Now(), "yyyy-MM-dd")

    Result: "2025-11-25"

  6. Format with time (12-hour):

    FormatDate(|->[AppointmentTime], "MMMM d, yyyy h:mm tt")

    If AppointmentTime = #15/03/2025 14:30:00#:

    Result: "March 15, 2025 2:30 PM"

  7. Format with time (24-hour):

    FormatDate(Now(), "dd/MM/yyyy HH:mm:ss")

    Result: "25/11/2025 14:30:45"

  8. Create a friendly relative date description:

    "Your subscription renews on " & FormatDate(|->[RenewalDate], "MMMM d")

    If RenewalDate = #15/01/2026#:

    Result: "Your subscription renews on January 15"

  9. Format expiration date for an offer:

    FormatDate(Now() + 30, "MMMM d, yyyy")

    Result: "December 25, 2025" (30 days from November 25)

  10. Add days to a date and format the result:

    "Payment is due by " & FormatDate(|->[InvoiceDate] + 30, "MMMM d, yyyy")

    If InvoiceDate = #15/02/2026#:

    Result: "Payment is due by March 18, 2026"

Tip: Any characters in the format string that are not format specifiers are included literally in the output. Use this to add separators, punctuation, or text between date components.

More topics