You need to sign in to do that
Don't have an account?
The_Fox
Problem with sforce.Util.ParseDate
Hi DevAngel or Benji,
I have in my opportunity defined two custom Date Field. I am in salesforce in (GMT+01:00) Central European Time (Europe/Brussels) Time Zone.
I am using Firefox 1.5.0.1 and when I am displaying through Alert javascript the Close Date of the opportunity the date is ok but when I am alerting the two custom date fields in the alert it is taking the day for the month and vice versa after putting the date through the sforce.Util.ParseDate. What could be the problem and the workaround.
My PC is Romance Time Zone
The code extract:
var oppCloseDate = "{!Opportunity_CloseDate}";
var oppSerSDate = "{!Opportunity_ServicesStartDate}";
var oppSerEDate = "{!Opportunity_ServicesCloseDate}";
var oppDate = Sforce.Util.ParseDate(oppCloseDate);
alert(oppDate);
alert(Sforce.Util.ParseDate(oppSerSDate));
alert(Sforce.Util.ParseDate(oppSerEDate));
Thanks for your help
I have in my opportunity defined two custom Date Field. I am in salesforce in (GMT+01:00) Central European Time (Europe/Brussels) Time Zone.
I am using Firefox 1.5.0.1 and when I am displaying through Alert javascript the Close Date of the opportunity the date is ok but when I am alerting the two custom date fields in the alert it is taking the day for the month and vice versa after putting the date through the sforce.Util.ParseDate. What could be the problem and the workaround.
My PC is Romance Time Zone
The code extract:
var oppCloseDate = "{!Opportunity_CloseDate}";
var oppSerSDate = "{!Opportunity_ServicesStartDate}";
var oppSerEDate = "{!Opportunity_ServicesCloseDate}";
var oppDate = Sforce.Util.ParseDate(oppCloseDate);
alert(oppDate);
alert(Sforce.Util.ParseDate(oppSerSDate));
alert(Sforce.Util.ParseDate(oppSerEDate));
Thanks for your help
For those who want to make Date difference (and then date shifting with the dateadd from sforce.util) here is some code
Devangel and Benjibasik you can take it and add it to sforce.util if you want (I think it is quite close to date add and shoul integrate easily):smileyhappy:
function DateDiff(p_Interval,p_Date_1, p_Date_2){
if(!Sforce.Util.IsDate(p_Date_1)){return "invalid date: '" + p_Date_1 + "'";}
if(!Sforce.Util.IsDate(p_Date_2)){return "invalid date: '" + p_Date_2 + "'";}
var dt1 = new Date(p_Date_1);
var dt2 = new Date(p_Date_2);
// get ms between dates (UTC) and make into "difference" date
var iDiffMS = dt2.valueOf() - dt1.valueOf();
var dtDiff = new Date(iDiffMS);
// calc various diffs
var nYears = dt2.getUTCFullYear() - dt1.getUTCFullYear();
var nMonths = dt2.getUTCMonth() - dt1.getUTCMonth() + (nYears!=0 ? nYears*12 : 0);
var nQuarters = parseInt(nMonths/3);
var nMilliseconds = iDiffMS;
var nSeconds = parseInt(iDiffMS/1000);
var nMinutes = parseInt(nSeconds/60);
var nHours = parseInt(nMinutes/60);
var nDays = parseInt(nHours/24);
var nWeeks = parseInt(nDays/7);
// return requested difference
var iDiff = 0;
switch(p_Interval.toLowerCase()){
case "yyyy": return nYears;
case "q": return nQuarters;
case "m": return nMonths;
case "y": // day of year
case "d": return nDays;
case "w": return nDays;
//case "ww":return nWeeks; // week of year // <-- inaccurate
case "h": return nHours;
case "n": return nMinutes;
case "s": return nSeconds;
case "ms":return nMilliseconds; // millisecond
default: return "invalid interval: '" + p_Interval + "'";
}
}