I am using date type variable

public Date arrivalDate {get;set;}

now my question is how we will initialize this variable in constructor in proper way, if I use this whats the meaning of 1,1,1.

arrivalDate = Date.newInstance(1,1,1);

If you looked into Date.newInstance() method

It says

newInstance(year, month, date)

Constructs a Date from Integer representations of the year, month (1=Jan), and day.

First parameter means it is year value, second parameter month value and lastly third one for day value

| improve this answer | |
  • thanks, is there another way to initialize ? – Yogesh Gupta Apr 15 '16 at 4:50
  • 1
    @YogeshGupta for initialize this is the best option.. if you want another option then you can assign Date.today() for current date.. if you want prev week date then use Date.TOday().addDays(-7) OR if you want future dates then use likeDate.Today.addDays(7) ... Here -7 means it will minus -7 from current date and +7 means it will add into current date – Ratan Paul Apr 15 '16 at 4:53
  • 1
    @YogeshGupta Note that most classes use a simple constructor (new X(some params)). Date, DateTime, and Time data types happen to be exceptions to this rule. Honestly, not sure why they decided to do this, except perhaps to force developers to choose between local times and GMT times. – sfdcfox Apr 15 '16 at 5:48
  • I just querying Date field and assign value in date variable, but in the UI its showing GMT format in text field, how can I convert it into Date 'dd-mm-yyyy' – Yogesh Gupta Apr 16 '16 at 10:55
  • @YogeshGupta can you ask this as a new question that will help other user as well – Ratan Paul Apr 16 '16 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.