Ask AI
Skip to main content

Relative date

Function: Relative date

This function helps you display dates in a more human-friendly way, converting a specific date into a phrase like "today," "yesterday," "tomorrow," or "2 days ago." This makes it easier for your users to quickly understand when an event occurred or will occur without needing to calculate the difference themselves.

Input

  • Date to check: The specific date you want to convert into a relative format. This could be a date from your database, a date entered by a user, or any other date value in your application. This input is required.

Output

  • Result: A piece of text representing the relative date. For example, if the 'Date to check' is today, the output will be 'today'. If it's a date in the past, it might be '2 days ago' or 'last week'. If it's in the future, it might be 'tomorrow' or 'in 5 days'.

Execution Flow

Real-Life Examples

Here are some examples of how you can use the "Relative date" function:

  1. Displaying a post's age on a blog:

    • Inputs:
      • Date to check: The creation date of a blog post (e.g., 2023-10-26 if today is 2023-10-27).
    • Result: The output will be "yesterday", making it easy for readers to see how recent the post is.
  2. Showing the due date for a task:

    • Inputs:
      • Date to check: The due date of a task (e.g., 2023-10-30 if today is 2023-10-27).
    • Result: The output will be "in 3 days", giving the user a quick overview of the task's urgency.
  3. Notifying users about an upcoming event:

    • Inputs:
      • Date to check: The date of an event (e.g., 2023-10-27 if today is 2023-10-27).
    • Result: The output will be "today", clearly indicating that the event is happening now.
  4. Tracking when a record was last updated:

    • Inputs:
      • Date to check: The last updated timestamp of a customer record (e.g., 2023-09-15 if today is 2023-10-27).
    • Result: The output will be "1 month ago", providing a concise summary of the record's freshness.