How to get current day in salesforce(Apex)

Please use format method of DateTime class to print day of week and day of month. Please see the below example which printing day of week and month to the debug log-

DateTime currentDateTime = System.now();
system.debug(currentDateTime); //prints 2022-11-24 12:49:19

String dayOfweek = currentDateTime.format('u');
system.debug(dayOfweek); //prints 4 (4 is for thursday)

String dayOfmonth = currentDateTime.format('d');
system.debug(dayOfmonth); //prints 24

Published by Sandeep Kumar

He is a Salesforce Certified Application Architect having 11+ years of experience in Salesforce.

Leave a Reply