Dates

Prev Next

Dates

The date type can store dates (beginning 1990-01-01), time of day (down to the second), combination of both (date and time) and an empty values called blank dates. B4P handles all numerals as double precision floating point numbers. This means that numerals can handle both whole numbers and numbers with decimal digits behind. Two subtypes are suppported:

  • Dates with text represenatations
  • Plain dates (don't confuse with blank dates)

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. Following sub-types are supported for dates:
Dates read in from tables (if reading data as dates is activated with 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: 2024-07-14  Date only: 2024-07-14  Time only:

For input value      : now
  Date: 2024-07-14 10:07:35  Date only: 2024-07-14  Time only: 10:07:35

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
Try it yourself: Open LAN_Features_data_types_dates.b4p in B4P_Examples.zip. Decompress before use.