Built-in Functions → dateTrunc

dateTrunc() is a scalar date function that returns a date truncated so as to remove specified smaller units.

Note

dateTrunc() returns the rounded value of a timestamp to the interval needed according to string part. Suppose $current_time evaluates to 8/25/19 11:28:44 AM. Then, dateTrunc($currentTime, 'day') would return 8/25/19 12:00:00 AM.

The allowed values for string part are:

  • millisecond
  • second
  • minute
  • hour
  • day
  • month
  • year

Signature

dateTrunc(date exp, string part)

The following table illustrates the dateTrunc() parameters:

ParameterDescription
date expdate value to truncate
string partstring units to truncate date exp to

Returns

date

Example

Truncate the current time, setting hours to 0 (12am).

dateTrunc($currentTime, 'day')