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 this.

i have custome object in that object senderdate field is available with datetime type. suppose this filed data is

2013-08-02 00:20:00
2013-08-02 01:40:00
2013-08-02 00:20:00
2013-08-04 00:20:00

i want to access all row with same date i don't want time consideration.

i.e senderdate= 2013-08-02
it should display me 3 rows..
  • DATEVALUE is a Formula function, it can not be used in Apex, only in Visualforce, Custom Formula Fields, Validation Rules etc. You need to use the approach described in mast0r answer. – Andrew Fawcett Aug 7 '13 at 8:28

You can use a date() method of the Datetime object:

System.debug('date=' + (System.now()).date());

Alternatively you can use valueOf() method of Date object:

System.debug('date=' + Date.valueOf(System.now()));

Is SOQL you can use a Date variables to compare a CreatedDate for example:

Date d = System.today();

List<account> a = [Select Id From Account Where CreatedDate = :d];

Datetime Methods

Date Methods

| improve this answer | |
  • if i use System.now()).date() it is giving me date plus 00:00:00 for time. – Jayant Jadhav Aug 7 '13 at 8:25
  • @JayantJadhav Yes, this is a new Date object. – Sergej Utko Aug 7 '13 at 8:28
  • ya can i use date() function in soql. ex: – Jayant Jadhav Aug 7 '13 at 9:01
  • 1
    @JayantJadhav No, use just TODAY keyword salesforce.com/us/developer/docs/officetoolkit/Content/… – Sergej Utko Aug 7 '13 at 9:08
  • 1
    Actually, if you use Date.valueOf, it does not strip out time information, strangely enough. Try system.debug(Date.valueOf(Datetime.now())) and see for yourself. – Adrian Larson Apr 22 '15 at 15:02

Simply use

System.debug('date=' + (System.now()).date().format());

this will result 2013-08-02 00:20:00 to 02-08-2013

| improve this answer | |

You can Use this

<apex:outputText value="{0,date,yyyy.MM.dd}">
   <apex:param value="{!MyVar.Holiday_Date__c}"/>

Where ..... instead of MyVar.Holiday_Date__C use your DateTime variable name.

| improve this answer | |
System.debug('date='System.today()); will return current date where as 

System.debug('date='+System.now());   will retugn current date and time
| improve this answer | |

Use String Class Split to trim time
returns USER_DEBUG|[1]|DEBUG|2017-10-25

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.