Problems with Date Formats in the Deployment Server

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:
output
                                               Figure1: Demonstrating the Requirement.

Server Machine-Output:

output
                                         Figure2: Demonstrating Server Machine-Output.

problem

Approaches to solve this problem.

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

code

Calling the method:
code
After doing these modification the problem got resolved and the output was as shown below on Prod Server:
output
                                       Figure 3: Demonstrating Server Machine- Correct Output.