Questions tagged [date]
A value that indicates a particular day. Unlike Datetime values, Date values contain no information about time
654
questions
54
votes
8
answers
60k
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?
23
votes
2
answers
29k
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 ...
20
votes
3
answers
51k
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?
19
votes
2
answers
16k
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()?
18
votes
3
answers
30k
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?
15
votes
4
answers
81k
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....
14
votes
4
answers
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
2
answers
501
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
4
answers
4k
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 ...
10
votes
2
answers
90k
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 |...
10
votes
1
answer
37k
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
...
9
votes
5
answers
31k
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="...
9
votes
3
answers
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
1
answer
6k
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
2
answers
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
2
answers
36k
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
4
answers
32k
views
i want to access only date from 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 ...
8
votes
2
answers
13k
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
1
answer
11k
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 ...
8
votes
2
answers
2k
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 ...
8
votes
1
answer
441
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
3
answers
6k
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
1
answer
477
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'...
7
votes
1
answer
95
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
2
answers
40k
views
Converting Date to DateTime
Added due date on case which is a date field. Trying to get this as dateTime and here is my code:
case c = [select id, caseNumber, Due_Date__c, status, type from case limit 1];
Date i = (c....
6
votes
1
answer
3k
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
1
answer
12k
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 ...
6
votes
1
answer
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
1
answer
2k
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
6
votes
2
answers
10k
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
1
answer
6k
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
1
answer
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
1
answer
18k
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
1
answer
2k
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
2
answers
3k
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
1
answer
517
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
1
answer
4k
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
2
answers
2k
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
2
answers
488
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
4
answers
17k
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 =...
5
votes
1
answer
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
1
answer
3k
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
2
answers
2k
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
1
answer
4k
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
1
answer
2k
views
SOQL: converting Date functions return values to specific timezone
SOQL Date functions CALENDAR_YEAR and CALENDAR_MONTH return values as UTC Timezone values. How to convert those values to specific Timezone, like Europe/Berlin ?
Example time: 2014.07.01 00:00 , ...
5
votes
2
answers
13k
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
2
answers
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
1
answer
821
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
3
answers
21k
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
1
answer
2k
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 ...