Skip to main content
added 40 characters in body; edited tags
Source Link
Pranay Jaiswal
  • 36.4k
  • 17
  • 79
  • 138

i want to pass date into newInstance method of datetime class then i will get date of week.when i have given static date it's working fine but when i try to pass dynamically i am getting error please share you ideas.

Working Part:

Datetime dt = DateTime.newInstance(2018, 9, 20); String dayOfWeek=dt.format('EEEE'); System.debug('Day : ' + dayOfWeek);

Datetime dt = DateTime.newInstance(2018, 9, 20);
String dayOfWeek=dt.format('EEEE');
System.debug('Day : ' + dayOfWeek);

Not working Part:

i am getting dates from external system so i can't assign statically here i am facing problem

String s1 = '2018-09-21'; String target = '-'; String replacement = ','; String s2 = s1.replace(target, replacement); Datetime dt = DateTime.newInstance(s2); String dayOfWeek=dt.format('EEEE'); System.debug('Day : ' + dayOfWeek);

String s1 = '2018-09-21';
String target = '-';
String replacement = ',';
String s2 = s1.replace(target, replacement);
Datetime dt = DateTime.newInstance(s2);
String dayOfWeek=dt.format('EEEE');
System.debug('Day : ' + dayOfWeek);

i want to pass date into newInstance method of datetime class then i will get date of week.when i have given static date it's working fine but when i try to pass dynamically i am getting error please share you ideas.

Working Part:

Datetime dt = DateTime.newInstance(2018, 9, 20); String dayOfWeek=dt.format('EEEE'); System.debug('Day : ' + dayOfWeek);

Not working Part:

i am getting dates from external system so i can't assign statically here i am facing problem

String s1 = '2018-09-21'; String target = '-'; String replacement = ','; String s2 = s1.replace(target, replacement); Datetime dt = DateTime.newInstance(s2); String dayOfWeek=dt.format('EEEE'); System.debug('Day : ' + dayOfWeek);

i want to pass date into newInstance method of datetime class then i will get date of week.when i have given static date it's working fine but when i try to pass dynamically i am getting error please share you ideas.

Working Part:

Datetime dt = DateTime.newInstance(2018, 9, 20);
String dayOfWeek=dt.format('EEEE');
System.debug('Day : ' + dayOfWeek);

Not working Part:

i am getting dates from external system so i can't assign statically here i am facing problem

String s1 = '2018-09-21';
String target = '-';
String replacement = ',';
String s2 = s1.replace(target, replacement);
Datetime dt = DateTime.newInstance(s2);
String dayOfWeek=dt.format('EEEE');
System.debug('Day : ' + dayOfWeek);
Source Link
Sfdc
  • 43
  • 3
  • 8

How to pass Date dynamically to newInstance method of Datetime

i want to pass date into newInstance method of datetime class then i will get date of week.when i have given static date it's working fine but when i try to pass dynamically i am getting error please share you ideas.

Working Part:

Datetime dt = DateTime.newInstance(2018, 9, 20); String dayOfWeek=dt.format('EEEE'); System.debug('Day : ' + dayOfWeek);

Not working Part:

i am getting dates from external system so i can't assign statically here i am facing problem

String s1 = '2018-09-21'; String target = '-'; String replacement = ','; String s2 = s1.replace(target, replacement); Datetime dt = DateTime.newInstance(s2); String dayOfWeek=dt.format('EEEE'); System.debug('Day : ' + dayOfWeek);