Dates
Date and time related utility functions.
today
Returns today's date as a DateTime object. Source
Syntax:
Parameters: None
Returns: DateTime
Example:
todayAsString
Returns today's date as string. By default, it returns the date in ISO format. The output format can be changed by the $pattern
parameter. Source
Syntax:
Parameters: $pattern
: How to format the output string. The default value is Y-m-d
Returns: string
Example:
yesterday
Returns yesterday's date as a DateTime object. Source
Syntax:
Parameters: None
Returns: DateTime
Example:
yesterdayAsString
Returns yesterday's date as string. By default, it returns the date in ISO format. The output format can be changed by the $pattern
parameter. Source
Syntax:
Parameters: $pattern
: How to format the output string. The default value is Y-m-d
Returns: string
Example:
tomorrow
Returns tomorrow's date as a DateTime object. Source
Syntax:
Parameters: None
Returns: DateTime
Example:
tomorrowAsString
Returns tomorrow's date as string. By default, it returns the date in ISO format. The output format can be changed by the $pattern
parameter. Source
Syntax:
Parameters: $pattern
: How to format the output string. The default value is Y-m-d
Returns: string
Example:
differenceInDays
Returns the difference in days between two dates. Source
Syntax:
Parameters: $startDate
: The first date
$endDate
: The second date
Returns: int
Example:
differenceInDaysFromString
Returns the difference in days between two dates that are defined as strings. Source
Syntax:
Parameters: $startDate
: The first date as string
$endDate
: The second date as string
Returns: int
Example:
addDaysToDate
Adds days to the original date and returns the new date as a DateTime object. Source
Syntax:
Parameters: $originalDate
: The base date as string
$days
: Number of days to add
Returns: DateTime
Example:
addMinutesToTime
Adds minutes to the original time and returns the new time as a DateTime object. Source
Syntax:
Parameters: $originalDate
: The base time as string
$minutes
: Number of minutes to add
Returns: DateTime
Example:
getLastDayOfMonth
Returns the last day of the month based on the specified date. Source
Syntax:
Parameters: $actualDate
: The actual date as string
Returns: DateTime
Example:
timestampToDateTime
Converts the given Unix timestamp to a DateTime object. Source
Syntax:
Parameters: $timestamp
: The Unix timestamp to convert
Returns: DateTime
Example:
dateToTimestamp
Returns the Unix timestamp representation of a given date. Source
Syntax:
Parameters: $dateStr
: The date in string format to convert
Returns: int
Example:
getTimeDifferenceInMinutes
Gets the difference between two date times in minutes. Source
Syntax:
Parameters: $startTime
: The start time in string format
$endTime
: The end time in string format
Returns: int
Example:
getDayOneWeekFromNow
Returns the date one week from now. Source
Syntax:
Parameters: None
Returns: DateTime
Example:
Last updated