Questions tagged [date]

A value that indicates a particular day. Unlike Datetime values, Date values contain no information about time

Filter by
Sorted by
Tagged with
48
votes
8answers
36k views

How Can I Tell the Day of the Week of a Date?

I'd like to build in some logic based on the weekday (e.g. Monday, Tuesday, Wednesday) of a given date. How can I identify the date, using either formulas or Apex code?
17
votes
2answers
15k views

Does LAST_N_DAYS:1 Include TODAY?

I would like to ask about the definition of LAST_N_DAYS:n For the number n provided, starts 00:00:00 of the current day and continues for the past n days. Is CreatedDate = LAST_N_DAYS:1 equal ...
16
votes
3answers
22k views

Apex: getting yesterday's date

I know that you get today's date like this: Date.today(). What would be the best solution to get yesterday's date?
16
votes
3answers
35k views

How to calculate the time between two DateTimes?

I know that you can use daysBetween() for two Date objects, but what would I use to calculate the elapse time in seconds between two DateTime objects?
15
votes
2answers
9k views

System vs Date/DateTime class

Is there any difference between System.today() and Date.today()? Similarly, is there any difference between System.now() and DateTime.now()?
14
votes
4answers
2k views

What is the purpose of Datetime.dateGmt() function?

In casual testing, I can see these give different results: //assemble from component parts Datetime now = System.now(); Date today = Date.newInstance(now.yearGmt(), now.monthGmt(), now.dayGmt()); //...
13
votes
2answers
374 views

DateTime.format() unexpected behavior

Hi I am executing following code snippet and after 26/12/2015, date shifted to one year ahead of expected. Date startDate = Date.parse('12/24/2015'); Date endDate = Date.parse('12/30/2015'); while(...
12
votes
4answers
2k views

Datepicker widget location issue

I have a visualforce page with a standard controller of a custom object, and within the page and inputfield that is tied to a custom date field of said object. I've dropped the VF page into the page ...
9
votes
3answers
46k views

How to set a Date in apex test class?

I have written a test class in which I just want to set one date field. How can I achieve this? I am not able to set the value using the following code: Account acc=new Account(); acc....
9
votes
3answers
3k views

Getting a birthday workflow to work

I am looking to run a workflow off a birthdate and notify my user that this birthday is coming up in 10 days. I am using this formula: (MONTH( Birthdate)) = MONTH(TODAY()) && (DAY( Birthdate))...
9
votes
1answer
5k views

How to pass Date from Lightning to Apex

In Lightning component I have attribute and input for date: <aura:attribute name="myDate" type="Date"/> <!-- ... --> <ui:inputDate aura:id="my-date" labelClass="slds-form-...
9
votes
2answers
2k views

New HTML5 Apex:Input issue

I'm trying to use new Input and InputField with type attribute. I need to use the date or datetime type as follow: <apex:input value="{!birthdayDate}" type="date" styleClass="select-box"/> ...
8
votes
1answer
26k views

Convert DateTime to Date

I want to Convert DateTime into Date I have been trying this out ..below is the code snippet public void searchSFDC() { DateTime lastModDate ; for(sObject resultSet : searchResults[0]) { // ...
8
votes
1answer
9k views

SOQL How to select WHERE = 2 months ago

I'm tying to retrieve data from the 2 months ago. I tried WHERE = LAST_N_MONTHS:2 but this returns data from last month too. So for now I want everything from 1st July - 31st July. This needs to ...
8
votes
2answers
19k views

How To Format Datetime like 2017-01-10T14:53:55.000+0000?

Using Apex, how can I format a Datetime variable the same way it is displayed in SOQL result? It seems that SOQL uses the UTC format. When I run the following query SELECT CreatedDate FROM Account ...
8
votes
1answer
175 views

Which date format to use with inputs for the Quick Actions REST API? (INVALID_TYPE_ON_FIELD_IN_RECORD)

I'm receiving the error INVALID_TYPE_ON_FIELD_IN_RECORD when invoking a custom sobject quick action to create a record and its payload specifies a Date or DateTime field as an input value. For ...
7
votes
2answers
49k views

How to convert string to Date in apex?

What is wrong with this format while am upserting the date in an object? Route__c r =new Route_c(); r.Plan_Date__c = date.parse(strDate); upsert r; In the debug log, I get the error as |...
7
votes
2answers
1k views

DateTime.Format() Documentation example causes exception

I'm trying to get a DateTime to format into a value to be used in a dynamic query. For some reason, the documentation snippet on how to format a DateTime for a query is giving me an exception. Im ...
7
votes
1answer
8k views

Convert Date to milliseconds and milliseconds to Date

I am getting date into JSON as below : date=1382166999 It seems that date has been returned in milliseconds format. Can anyone please suggest the way to convert it into normal date format and vice ...
7
votes
3answers
5k views

Get list of Date locales

It is possible to change the locales used for Date for users in the Admin. For example, Ireland is dd/mmy/yy The US is m/d/yyyy Is there anywhere where I can get a list of all locales? Thanks
7
votes
1answer
91 views

Set collection doesn't always enforce uniqueness with the Date datatype? Does the following example seem correct?

Consider the following unit test: @istest public static void datetests2() { Set<Date> dts = new Set<Date>(); dts.add(DateTime.now().Date()); dts.add(DateTime.now().addHours(1)....
6
votes
1answer
2k views

Cleaner way to get last day of previous month? [duplicate]

Is there a cleaner way of getting the last day of the previous month? Also, is the Date.addMonth() function smart enough to deal with months having different numbers of days? As in, if I subtract 1 ...
6
votes
1answer
10k views

Displaying date in visualforce force page in required format

I have a date fields which on displaying on VF page displays like 12/10/2012. But i want to display it like December 10, 2012. How can i do it? i am not getting the easy way.
6
votes
5answers
25k views

i want to access only date form datetime

If i used System.debug('date='+DATEVALUE(System.now())); in developer console i am getting error msg by saying: method does not exist or incorrect signature for DATEVALUE(datetime) How i can do ...
6
votes
2answers
9k views

Date Picker in Visualforce page using Lightning design system

I am trying to use date picker in ligtning design system and and using the idea explained in this link to do it: Lightning (SLDS) styling for calendar This works fine in the browser on the desktop ...
6
votes
4answers
18k views

Lightning:input type=“date”: how to change the date fomat - Summer'18

I'm trying to change date format of this component but I dont find any attribute (like ui:inputDate has) to change the date format. <lightning:input type="date" name="input8" label="Dates" value="...
6
votes
1answer
4k views

Using a specific dynamic date in a SOQL query where clause

I am trying to select a set of records in a batchable class that have expiration dates that are 7 or 30 days out. For the rest of the post I will only show 30 for brevity. I tried setting my query ...
6
votes
1answer
306 views

Test.setCreatedDate not working in SOQL Query with condition date set in future

I have an issue with Querying a record in a unit test with a custom set createdDate using the method Test.setCreatedDate(); static testMethod void test() { Account a = new Account(name='myAccount'...
6
votes
1answer
1k views

Salesforce Dates Incorrectly Formatting

So I have an interesting issue with dates. Basically the format method for the month of December seems to be broken for 2014 and 2015. Running the following code for the years of 2015 and below fails ...
6
votes
1answer
14k views

SOQL query filter WHERE by month

I have a custom object having a Date field Expense__Date__c I need to perform a soql query on the custom object where Expense__Date__c = THIS_MONTH So my query looks like List<CustomObj__c> ...
6
votes
1answer
1k views

URL hacking a report to pass a Date Literal filter value vs an actual date

Though not well documented by Salesforce, it's a well known fact that record pages and saved reports can be dynamically altered by passing URL parameters. For example, with a tabular report whose ...
6
votes
2answers
2k views

What is the correct way to check if two dates overlap

I have 2 object. They both have a start date and an end date. How can I check if they overlap? now I have: if((item1.DateStart__c >= item2.DateStart__c && item1.DateStart__c <= item2....
5
votes
1answer
390 views

Apex - Getting list of dates in month - CPU timeout

I am getting a CPU timeout from my loop. I have checked the debug logs and my start and end dates have the correct dates in them. I have tried setting the condition to be dtoday.adddays(3) just as a ...
5
votes
1answer
2k views

Date.newInstance() bug?

I was having issues with a method that was repeatedly printing out wrong dates, when I executed this in anonymous apex Date foo = date.newinstance(2016, 27, 7);//year, month, day system.debug(foo); ...
5
votes
2answers
461 views

Date Format in VisualForce

How can I display today's date in format like Monday December, 29th 2014 modifying this <apex:outputText value="{0,date,MM'/'dd'/'yyyy}"> <apex:param value="{!today()}" /> </apex:...
5
votes
1answer
1k views

What are the minimum and maximum valid dates in Salesforce?

What are the minimum and maximum valid dates in Salesforce? What is the valid date range in Apex, SOQL or SOAP API? It is hard to find anything in the documentation
5
votes
2answers
1k views

replacing LAST_MONTH

I have some code that depends on LAST_MONTH. Something like: select .... date__c .. FROM myTable__c where date__c = LAST_MONTH This code, as I understand, returns a result set constrained to ...
5
votes
1answer
4k views

Variable doesn't exist :Date

i write a small apex code snippet. if(v.dataType == 'Date') { System.debug('date is'+mapField.get(field1.name)); System.debug('field is'+field1); String str = mapField.get(field1....
5
votes
1answer
2k views

Lightning Component - pass variables from component to apex & get result back

I'm trying to pass a date field from a component to apex class and then return a string to my component. But I can't figure it out. Here is the detail of my code : lf_reports_controller.apxc ...
5
votes
2answers
524 views

DateTime.addMonths skips a month (from feb to mar)

I'm writing some code to get each months name between a start and an end date. This works fine for most months - except February into march, and november - december. Heres the code : Date startDate ...
5
votes
2answers
11k views

Date is showing a different date than the Date/Time Field

I have an issue when entering a date/time into a date field where the date increases by 1 day when after a certain time. Example would be 1/1/13 5:23PM PST converting to 1/2/13. This also occurs ...
5
votes
1answer
3k views

One day less than original date while uploading data in salesforce

I am importing data via a CSV file. In CSV file the date is 15/08/2015(dd/mm/yyyy) but when i check it in salesforce it is 14/08/2015(dd/mm/yyyy). The date is always one day less than original date. I ...
5
votes
2answers
1k views

Date literals not working in batch apex?

SOQL: [SELECT Id,Name FROM Account WHERE createddate=THIS_MONTH] This query is working fine when it is called from button, but it is unable to filter according to the created date when it is invoked ...
5
votes
1answer
552 views

Why is the inconsistency with Close Month?

I have created a report that gives the closed opptys of previous years. When trying to understand, I get a wrong: Summarize by Close Month option, as it shows the last month of 2012 as the close ...
4
votes
3answers
13k views

How to Get the Current System Time using SOQL

For tests proposes, I need to get the current system date. On Oracle we could use: SELECT SYSDATE FROM DUAL On SQL SERVER, we can use: SELECT GETDATE() AS CurrentDateTime How to query the system ...
4
votes
1answer
1k views

Is a TODAY() value in a formula field updated every day?

I want to use TODAY() in a formula field to calculate a person’s age based on the value in their date of birth field. Then I need to pull this field into a report. Will the TODAY() value be updated ...
4
votes
3answers
9k views

Date Formula to Calculate date excluding weekends

I have a formula that is calculating the date from another date field + number of days and returning a date. test census dates field = Confirmed_Enrolled_Date__c + 16 I want to exclude weekends ...
4
votes
4answers
12k views

How to resolve the Invalid Date error in Apex while uploading CSV file?

I am trying to upload the CSV file via Apex programming I am getting an error like Invalid Date Error. Please find the screenshot for more details. I have given code like this site.Approved_Date__c =...
4
votes
1answer
9k views

Process Builder - Add Minutes,Hours to Event End Date

I want to make the Event End Date as NOW()+60 Mins in process builder while creating a new Event record. But It is adding 60 DAYS even though Event End date is date/time field. How do I add minutes ...
4
votes
2answers
3k views

Passing Date field from Lightning component to Apex controller shows null

I have a custom salesforce object with a Date field. I am creating a new object of this type in a Lightning component, and trying to push this to the server. The objects are stored in a component ...

1
2 3 4 5
12