The date type can store the following:
In B4P code, dates are created using the following functions listed below.
Function name | Description |
---|---|
date() | Depending on the string value provided, it returns a date, date and time, time only, or blank date. |
pure date() | Works like date, but discards thhe time information. Output is either a date or blank date. |
date time() | Works like date. If input is not a blank, and if no time of day is provided, then 00:00:00 (midnight) is assumed as time of day. |
time() | This function discards and returns the time only. A blank date (and not 00:00:00) is returned if the input is a blank date. |
Simple and valid examples are: date( 14.07.2020 ), date( "2020-07-04" ), date( today ). The values provided in the date functions are string constants.
Please note that quotation marks (no matter if single or double) are required for the 2nd example because of the hyphens which would otherwise be treated as
minus signs where 7 and 4 are subtracted from 2020.
Reading dates from tables as dates and not as strings can be activated using the function call table configure().
// Following assignments are still strings (text)
a[0] = "July 14. 2021";
a[1] = '20:15:00';
a[2] = "2022 August 01 22:15";
a[3] = today; // Must be lower case
a[4] = now; // "
a[5] = '' ; // Blank date
for all variables( a[], b[] )
{
c[] = date( b[] );
d[] = pure date( b[] );
e[] = time ( b[] );
echo(new line, "For input value : ", b[] );
echo(" Date: ", c[]," Date only: ", d[], " Time only: ", e[]);
}
echo( new line, Additional Features );
echo(date("2020 / 12 / 31 15:00")+1); // Date and time
echo(date time("2020-12-31")); // Add a time (default 00:00:00)
echo(time("2020-12-31 15:00")); // Time
echo(time("2020-12-31 15:00")+1/24); // Time, 1 hour later
echo(pure date("31. Dezember 2021")+1); // Numeral
For input value : July 14. 2021
Date: 2021-07-14 Date only: 2021-07-14 Time only:
For input value : 20:15:00
Date: 20:15:00 Date only: Time only: 20:15:00
For input value : 2022 August 01 22:15
Date: 2022-08-01 22:15:00 Date only: 2022-08-01 Time only: 22:15:00
For input value : today
Date: 2025-09-21 Date only: 2025-09-21 Time only:
For input value : now
Date: 2025-09-21 15:06:52 Date only: 2025-09-21 Time only: 15:06:52
For input value :
Date: Date only: Time only:
Additional Features
2021-01-01 15:00:00
2020-12-31 00:00:00
15:00:00
16:00:00
2022-01-01