0

I have this code to get DateTime from database :

  private DateTime? GetLastWorkOrderFinishedDate(Guid scheduleId)
    {

        return _workOrders.Where(row => row.ScheduleId == scheduleId ).FirstOrDefault()?.CompletedDate;
    }

it return 2016-09-04 when user click to a button . but I have a job that runned every 10 minutes and that job call Above code but it return wrong dateTime 14/06/1395 .

the second value is persian Date but I dont know why ?

what is the problem ?

updated:

the value from database :

enter image description here

work question
  • 321
  • 2
  • 11

1 Answers1

1

As we understood the problem is related to the CurrentCulture of the threads. The CurrentCulture seems to be fa-IR and that's why the the returned date is Persian.

There are different workarounds to set default Culture, here are two of them:

CultureInfo.DefaultThreadCurrentCulture = new CultureInfo('en-US');

Or just set the Culture for the CurrentThread as you tried:

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

Ali Bahrami
  • 5,935
  • 3
  • 34
  • 53