Date & Time
To set a specific date, you can use the constructors of the DateTime structure or the ToDateTime functions (see more details in the "Conversion") or the DateSerial function (discussed below).
For example, to create a date and time using constructors, you can use the following code:
new DateTime(year, month, day, hours, minutes, seconds);
When using the date conversion functions from this section, the time information is by default preserved. To remove the time from the date, you can use the Format or FormatDateTime functions. More detailed information about these functions is presented in the "Formatting" section.
As an example, the [Employees.BirthDate] field from the demonstration database will be used in the functions.
[Employees.BirthDate] = 27.01.1986
AddDays
| Function | Parameters | Return value |
|---|---|---|
AddDays |
DateTime date, double value |
DateTime |
Adds the specified number of days (value) to the date date and returns a new date.
Example:
AddDays(new DateTime(2024,4,2), 2) = 4/4/2024 12:00:00 AM
AddDays(ToDateTime("4/2/2024"), 2) = 4/4/2024 12:00:00 AM
AddDays([Employees.BirthDate], 2) = 1/29/1986 12:00:00 AM
AddHours
| Function | Parameters | Return value |
|---|---|---|
AddHours |
DateTime date, double value |
DateTime |
Adds the specified number of hours (value) to the date date and returns a new date.
Example:
AddHours(new DateTime(2024,4,2,5,30,5), 1) = 4/2/2024 6:30:05 AM
AddHours(ToDateTime("4/2/2024 5:30:05"), 1) = 4/2/2024 6:30:05 AM
AddHours([Employees.BirthDate], 1) = 1/27/1986 1:00:00 AM
AddMinutes
| Function | Parameters | Return value |
|---|---|---|
AddMinutes |
DateTime date, double value |
DateTime |
Adds the specified number of minutes (value) to the date date and returns a new date.
Example:
AddMinutes(new DateTime(2024,4,2,5,30,5), 10) = 4/2/2024 5:40:05 AM
AddMinutes(ToDateTime("4/2/2024 5:30:05"), 10) = 4/2/2024 5:40:05 AM
AddMinutes([Employees.BirthDate], 10) = 1/27/1986 12:10:00 AM
AddMonths
| Function | Parameters | Return value |
|---|---|---|
AddMonths |
DateTime date, int value |
DateTime |
Adds the specified number of months (value) to the date date and returns a new date.
Example:
AddMonths(new DateTime(2024,4,2,5,30,5), 2) = 6/2/2024 5:30:05 AM
AddMonths(ToDateTime("4/2/2024 5:30:05"), 2) = 6/2/2024 5:30:05 AM
AddMonths([Employees.BirthDate], 2) = 3/27/1986 12:00:00 AM
AddSeconds
| Function | Parameters | Return value |
|---|---|---|
AddSeconds |
DateTime date, double value |
DateTime |
Adds the specified number of seconds (value) to the date date and returns a new date.
Example:
AddSeconds(new DateTime(2024,4,2,5,30,5), 10) = 4/2/2024 5:30:15 AM
AddSeconds(ToDateTime("4/2/2024 5:30:05"), 10) = 4/2/2024 5:30:15 AM
AddSeconds([Employees.BirthDate], 10) = 1/27/1986 12:00:10 AM
AddYears
| Function | Parameters | Return value |
|---|---|---|
AddYears |
DateTime date, int value |
DateTime |
Adds the specified number of years (value) to the date date and returns a new date.
Example:
AddYears(new DateTime(2024,4,2,5,30,5), 3) = 4/2/2027 5:30:05 AM
AddYears(ToDateTime("4/2/2024 5:30:05"), 3) = 4/2/2027 5:30:05 AM
AddYears([Employees.BirthDate], 3) = 1/27/1989 12:00:00 AM
DateDiff
| Function | Parameters | Return value |
|---|---|---|
DateDiff |
DateTime date1, DateTime date2 |
TimeSpan |
Returns the interval (number of days, hours, minutes, seconds) between two dates.
Example:
DateDiff(new DateTime(2024,4,2,5,0,0), new DateTime(2025,1,2,5,30,5)) = -275.00:30:05
DateDiff(ToDateTime("1/2/2025 5:30:05"), ToDateTime("4/2/2024 5:00:00")) = 275.00:30:05
DateDiff(ToDateTime("4/2/2024 5:00:00"), [Employees.BirthDate]) = 13945.05:00:00
DateSerial
| Function | Parameters | Return value |
|---|---|---|
DateSerial |
int year, int month, int day |
DateTime |
Creates a new DateTime value from the specified year, month and day.
Another available method to set a specific date.
Example:
DateSerial(2024,4,2) = 4/2/2024 12:00:00 AM
Day
| Function | Parameters | Return value |
|---|---|---|
Day |
DateTime date |
int |
Gets the day of the month (1-31) represented by the specified date.
Example:
Day(new DateTime(2024,4,2)) = 2
Day(ToDateTime("4/2/2024")) = 2
Day([Employees.BirthDate]) = 27
DayOfWeek
| Function | Parameters | Return value |
|---|---|---|
DayOfWeek |
DateTime date |
string |
Gets the localized name of the day of the week represented by the specified date.
Example:
DayOfWeek(new DateTime(2024,4,2)) = "Tuesday"
DayOfWeek(ToDateTime("4/2/2024")) = "Tuesday"
DayOfWeek([Employees.BirthDate]) = "Monday"
DayOfYear
| Function | Parameters | Return value |
|---|---|---|
DayOfYear |
DateTime date |
int |
Gets the day of the year (1-365) represented by the specified date.
Example:
DayOfWeek(new DateTime(2024,4,2)) = 93
DayOfWeek(ToDateTime("4/2/2024")) = 93
DayOfWeek([Employees.BirthDate]) = 27
DaysInMonth
| Function | Parameters | Return value |
|---|---|---|
DaysInMonth |
int year, int month |
int |
Returns the number of days in the specified month and year.
Example:
DaysInMonth(2024, 4) = 30
Hour
| Function | Parameters | Return value |
|---|---|---|
Hour |
DateTime date |
int |
Gets the hour component (0-23) represented by the specified date.
Example:
Hour(new DateTime(2024,4,2,5,30,5)) = 5
Hour(ToDateTime("4/2/2024 5:30:05")) = 5
Hour([Employees.BirthDate]) = 0
Minute
| Function | Parameters | Return value |
|---|---|---|
Minute |
DateTime date |
int |
Gets the minute component (0-59) represented by the specified date.
Example:
Minute(new DateTime(2024,4,2,5,30,5)) = 30
Minute(ToDateTime("4/2/2024 5:30:05")) = 30
Minute([Employees.BirthDate]) = 0
Month
| Function | Parameters | Return value |
|---|---|---|
Month |
DateTime date |
int |
Gets the month component (1-12) represented by the specified date.
Example:
Month(new DateTime(2024,4,2)) = 4
Month(ToDateTime("4/2/2024")) = 4
Month([Employees.BirthDate]) = 1
MonthName
| Function | Parameters | Return value |
|---|---|---|
MonthName |
int month |
string |
Gets the localized name of the specified month (1-12).
Example:
MonthName(1) = "January"
Second
| Function | Parameters | Return value |
|---|---|---|
Second |
DateTime date |
int |
Gets the seconds component (0-59) represented by the specified date.
Example:
Second(new DateTime(2024,4,2,5,30,5)) = 5
Second(ToDateTime("4/2/2024 5:30:05")) = 5
Second([Employees.BirthDate]) = 0
Year
| Function | Parameters | Return value |
|---|---|---|
Year |
DateTime date |
int |
Gets the year component represented by the specified date.
Example:
Year(new DateTime(2024,4,2)) = 2024
Year(ToDateTime("4/2/2024")) = 2024
Year([Employees.BirthDate]) = 1986