There is sometimes the need of a project where you need to create a file i.e. .txt, .csv, .xlsx, etc. We use date time format as required for the project and everything works fine on the local machine but when we deploy on the server it starts showing server date time culture.
Problem Scenario
To create a File with information with date in yyyy-mm-dd format as shown below:
Local Machine-Expected Output:
Figure1: Demonstrating the Requirement.
Server Machine-Output:

Figure2: Demonstrating Server Machine-Output.

Approaches to solve this problem.
• yourDateTime.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)
• Creating a method to set the culture.

Calling the method:
After doing these modification the problem got resolved and the output was as shown below on Prod Server:

Figure 3: Demonstrating Server Machine- Correct Output.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Saurabh RaiPosted Apr 27, 2016, 3:16 AM
Nice
Upendra Pratap ShahiPosted Apr 26, 2016, 1:40 PM
nice one..