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. Aug 7, 2013 at 8:28

4 Answers 4


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

  • if i use System.now()).date() it is giving me date plus 00:00:00 for time. Aug 7, 2013 at 8:25
  • @JayantJadhav Yes, this is a new Date object. Aug 7, 2013 at 8:28
  • ya can i use date() function in soql. ex: Aug 7, 2013 at 9:01
  • 1
    @JayantJadhav No, use just TODAY keyword salesforce.com/us/developer/docs/officetoolkit/Content/… Aug 7, 2013 at 9:08
  • 2
    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, 2015 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


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.


You can use the Date.format method which:

"Converts the date to the local time zone and returns the converted date as a string using the supplied Java simple date format. If the time zone cannot be determined, GMT is used."

If you use System.now()).date().format() it will return something like 4/29/2021

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .