The date type can store the following:
Internally B4P handles dates and times as separate variable, which is different from Excel where time is coded as the fractional part of the date. Similar to numerals, two subtypes are suppported:
This data type can store pure dates (beginning 1990-01-01), time of day (down to the second), combination of both date and time of day, or blank dates which
are blank values neither containing dates or times.
Dates read in from tables (must activate it with calling the function table configure()) will automatically include their
text representations. The string representation will be discarded immediately when any kind of algorithmic operation
is applied, even if 0 days are added. No discardings take place on direct assignments
and transactions without calculations done, e.g. a[] = b[];.
In B4P code, dates are created using the following functions listed below and the dates are created as plain dates without memorized text representation.
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 ignores any time of day 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 will only use the time information. If the paramter contains a date only, then a blank date wil be returned. |
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.
// 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[] )
{
// The 'date' function converts input strings (text) into plain dates without preserving text
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-02-28 Date only: 2025-02-28 Time only:
For input value : now
Date: 2025-02-28 11:17:22 Date only: 2025-02-28 Time only: 11:17:22
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