function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Date issue with Analytics

Ok this is a strange two-part question/issue.


We have analytic snapshots that run once/week based on a report.  There are two issues we've just noticed with these.


1. For some reason, a couple of the date fields that are pulled from the report are storing an incorrect date.  The snapshot is due to run on a user in the PST timezone but the create and last modified dates from the report are storing an incorrect date in some cases.  If it's a record owned by a user in a different timezone, the snapshot is storing their date, not the person the context of the report is run as.


2. But more importantly, we have an apex controller class that pulls from the snapshot table a list of the snapshot dates.  These dates are showing up in each users local time zone settings when we need it to be consistent for all users.  So if the snapshot is run on 04-17-2010, then when we present the list of snapshots to all users they should see 04-17-2010.  not 04-18-2010 in some cases.

Here is the code that we're using to find the snapshot dates.  The goal is to create a selectlist for a VisualForce page to let the user choose which snapshot they want to run some analytics against.



	public List<SelectOption> getSnapShotDates() {
        List<SelectOption> optionList = new List<SelectOption>();
		Set <DateTime> snapdates = new Set <DateTime>();

// go get the most recent snapshot
		Analytics_Pipeline_Snapshots__c[] aps = 
			([SELECT Pipeline_Date__c 
			FROM Analytics_Pipeline_Snapshots__c 
			ORDER BY Pipeline_Date__c DESC LIMIT 1]);
// loop thru and create other snapshot dates one week before each one (up to 2 maximum)
		if (aps.size() > 0) {
			for (Integer i=0; i < 2; i++) {
				Datetime tempdate = datetime.newInstance(aps[0].pipeline_date__c.addDays(7 * -i).year(), 
														aps[0].pipeline_date__c.addDays(7 * -i).month(),
														aps[0].pipeline_date__c.addDays(7 * -i).day());
	            	new SelectOption(String.valueof(tempdate.format('yyyy-MM-dd')),

        return optionList;









yes, wrong date will come...

B'cos when you use datetime.format (in ur case  tempdate.format), it shows date in GMT format. So you have to write like this,


tempdate.format('yyyy- MM-dd','PST'))


to show it in a PST date format.



Hope this will work for you





Yes ... I've tried adding the 'PST' option as well to no avail.  I get the same wrong date when I use that and then login as a user in a different timezone.


actually .. I got the second issue solved by using newInstanceGMT instead and not using the 'PST' option.  So that seems to be working now.  But I'm still puzzled by the first issue