You need to sign in to do that
Don't have an account?
Ryan O'Sullivan
Date Rolling back on it's own
I have a problem where a date field is being grabbed and if said date field is entered as the first day of the month, when it is read out on the visualforce component it reads out the previous month.
I have it put out on the component as:
<tr>
<td class="aboveHalf">
<label class="custLabel bold"> MONTH OF {!reportDate}</label>
</td>
</tr>
The code governing reportDate is:
public String reportDate{
get{
if(reportDate == null){
Datetime cDate = report.Reporting_Date__c;
if(cDate != null){
reportDate = cDate.format('MMM yyyy');
}
}
return reportDate;
}
set;
}
I've added code as a work around to add one day to the given date such that it bumps it up to the correct month. But I still feel this is a salesforce problem with their Date.format function. Am I wrong to assume this or is this a known bug?
I have it put out on the component as:
<tr>
<td class="aboveHalf">
<label class="custLabel bold"> MONTH OF {!reportDate}</label>
</td>
</tr>
The code governing reportDate is:
public String reportDate{
get{
if(reportDate == null){
Datetime cDate = report.Reporting_Date__c;
if(cDate != null){
reportDate = cDate.format('MMM yyyy');
}
}
return reportDate;
}
set;
}
I've added code as a work around to add one day to the given date such that it bumps it up to the correct month. But I still feel this is a salesforce problem with their Date.format function. Am I wrong to assume this or is this a known bug?
What happens when the data is imported in is it converts to the Time Zone and Locale settings of the User that is viewing the Date/Time field in a particular record each time.
The value in salesforce is stored in GMT but while viewing on the UI it adjusts the value to users time zone. Since users time zone is (GMT-04:00) Eastern Daylight Time (America/New_York), it is showing a day lesser. However in the database the value is populated correctly.
All Answers
I think you need to put your timezone while converting a datetime instance into string.
Check this out.
What happens when the data is imported in is it converts to the Time Zone and Locale settings of the User that is viewing the Date/Time field in a particular record each time.
The value in salesforce is stored in GMT but while viewing on the UI it adjusts the value to users time zone. Since users time zone is (GMT-04:00) Eastern Daylight Time (America/New_York), it is showing a day lesser. However in the database the value is populated correctly.
In a SOQL query you can specify either a particular date or a date literal. A date literal is a fixed expression that represents a relative range of time, such as last month, this week, or next year.
dateTime field values are stored as Coordinated Universal Time (UTC). When a dateTime value is returned in Salesforce, it’s adjusted for the time zone specified in your org preferences. SOQL queries, however, return dateTime field values as UTC values. If you want to process these values in different time zones, your application might need to handle the conversion.
Please check the below links:
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm
https://help.salesforce.com/HTViewSolution?id=000004680&
https://paulforce.wordpress.com/2009/08/27/formatting-time-in-apex/
Please do let me know if it helps you.
Regards,
Mahesh