Date Datatypes in APEX
Chapter Topics
- Apex Data Types
- Integer Data Type in APEX
- Floating Point Data Type in APEX
- String Data Type in APEX
- Date Datatypes in APEX
- Time and DateTime Data Types in APEX
- Boolean Datatype in Salesforce
- ID & Blob Datatypes in APEX
- What is the Rule of Conversions in Apex?
- Enums in APEX
- sObjects in Salesforce
- Generic sObjects in Salesforce
- Collections in APEX
- Lists in APEX
- List Array Notation in APEX
- Lists Initialization in APEX
- Nested Lists in APEX
- Sets in APEX
- Sets Initialization And Methods
- Maps in APEX
- Map Initialization Methods in APEX
- Operators in Apex and Their Types
- Shorthand Operator
- Equality Operator
- Relational Operators(<,>,<=,>=)
What is the Date Data Type in Salesforce?
A variable of the Date Data Type in Apex is used to store a date that indicates a particular date. Date values contain no information about time. Dates in Apex are represented by the Date data type, which includes the day, month, and year information. This works great in situations when you have to work with dates, do computations, or compare dates without taking time into account. It is always advised to create date values with a system static method.
We can add or subtract an Integer value from a Date value, returning a Date value. Addition and subtraction of Integer values are the only arithmetic functions that work with Date values. However, we can’t perform arithmetic functions that include two or more Date values.
How to write date data type in Salesforce?
Declaration and Initialization
// Declaration
Date myDate;
// Initialization
myDate = Date.newInstance(2024, 5, 16); // Specific date
Date today = Date.today(); // Current date
Date parsedDate = Date.valueOf('2024-05-16'); // Parsing a date from string
Date Methods in Apex
There are various methods to use the Date Data Type in Apex:


Join our newsletter: Get daily update on Salesforce career insights & news!
Join Now!
Need more support?
Get a head start with our FREE study notes!
Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.