I have a field which is date field, I wanted the time value of that field. If I change the data type the value gets erased. How can I get the time for that field.

Please help

  • you can create a new formula field and display the day,month and year on that field
    – Ratan Paul
    Oct 6 '16 at 7:17
  • It is possible to make the old value displayed with time Oct 6 '16 at 7:22
  • Kunal.. what do you mean by old value. if this is date field then you can't get the time since date field field store only date not time. If it is datetime field then it store the date and time as well
    – Ratan Paul
    Oct 6 '16 at 7:26
  • I have a requirement where I wanted to capture the time of a date field which can only be done changing the date field to date/time field but I want time for old value which is not possible i think so Oct 6 '16 at 7:30

To answer your question let me put down 2 points:

  1. The Date field does store a value, but its value is set to 0 by default. Check this link
Date myDate = Date.newinstance(1960, 2, 17); 
System.debug(myDate); //**Output**: 1960-02-17 00:00:00
  1. If you want to change the data type from Date to Datetime, you will loose the data. Check this link

Only convert custom fields for which no data exists or you risk losing your data. Changing the data type of an existing custom field can cause data loss in the following situations:

  • Changing to or from type Date or Date/Time

So if you want to convert Date to Datetime and capture Datetime going forward, it would be ideal to first create a separate Datetime field, copy the value of the date field and then delete the date field from the system. You may run into issues if there is any code that references the Date field. In such case, you would have to first modify your code to remove the references to the Date field and add references to the new Datetime field.

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.