You need to sign in to do that
Don't have an account?
Raj R.
How to get the day of the week from the DateTime field?
Hi,
I am using the following code below to get the day of the week from the DateTime field, but I am finding that the day of the week is wrong. Essentially i am getting the ((day of the week) - 1)
For example:
I am using the following code below to get the day of the week from the DateTime field, but I am finding that the day of the week is wrong. Essentially i am getting the ((day of the week) - 1)
For example:
- For a DateTime value of 4/9/2016, i am getting Friday (when it is really on a Saturday)
- For a DateTime value of 4/12/2016, i am getting Monday (when it is really on a Tuesday)
//for simplicity assume dt variable is defined and set to 2016-04-09 00:00:00. String dateStr = dt.format('EEEE'); //use for debugging System.debug('Day of Campaign: '+dateStr+ ' Time: '+dt);
You can try this:-
Event et = [Select Id, StartDateTime From Event Limit 1];
getDayOfWeek(et.StartDateTime);
getDayOfWeek(DateTime dt) {
Datetime dt1 = DateTime.newInstance(dt, Time.newInstance(0, 0, 0, 0));
String dateStr = dt1.format('EEEE');
System.debug('Day of event: ' + dateStr);
}
Thanks
All Answers
Unfortunately, that is not working. Below you shall find another example of code that i am using. Any other thoughts?
I think the time zone difference between you and organization time, that is the reason you are getting next day.
Let me know if you need any help regarding this.
Thanks,
Vijay
You can pass the timezone and then can try - something like - You can have more information about the timezone here - You can go to the USER details and can find out in which time zone he is -
Pls, Let me know if further help is needed.
Thanks
Sumit Kumar Singh
You can try this:-
Event et = [Select Id, StartDateTime From Event Limit 1];
getDayOfWeek(et.StartDateTime);
getDayOfWeek(DateTime dt) {
Datetime dt1 = DateTime.newInstance(dt, Time.newInstance(0, 0, 0, 0));
String dateStr = dt1.format('EEEE');
System.debug('Day of event: ' + dateStr);
}
Thanks
Appreciate your feedback! All your ideas came together and helped me alot!