This course is currently a work in progress. Please join the waitlist to receive regular updates.

Date variables in apex

What is a date variable?

In Apex, you can use Date variables to store dates. A Date includes only the day, month, and year. It does not store the time (like hours, minutes, or seconds).

Date variables in Apex can be used to:

  • Store dates (e.g., delivery date).
  • Compare dates (e.g., check if one date is before or after another).
  • Find a future date (e.g., payment due date).
  • Calculate the number of days between two dates.

How to declare a date?

You can declare a date using the Date data type and the Date.newInstance method.

Loading...

In the above example:

  • The keyword Date is used to declare a Date variable.
  • The variable name myDate is used to store the date value.
  • The value 2024-12-01 is assigned to the variable myDate.

Try It Yourself

Loading...