1

The following code returns the time of the current date:

System.debug('Current date: ' + Date.today().toStartOfMonth());

Output:

2018-08-01 00:00:00

How to remove time from date?

6

only way I found is to keep the date format and remove the 00 from end

System.debug('Current date: ' + String.valueOf(Date.today()).removeEnd(' 00:00:00'));
3

Using the format method solve the issue.

System.debug('Current date: ' + Date.today().toStartOfMonth().format());

Output:

1-8-2018

1
  • format function returns the date in current timezone Aug 16 '18 at 10:11
2

Date.format() method returns the Date as a string using the locale of the context user

or if you need it in a specific format regardless User locale use something like Datetime.format('yyyy-MM-dd') or Datetime.format('yyyy-MM-dd', 'America/New_York')

e.g.

Date d = Date.today().toStartOfMonth();
System.debug( Datetime.newInstance(d.year(), d.month(), d.day()).format('yyy-MM-dd') );

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.