Unnikrishnan Unnikrishnan - 8 months ago 35
C# Question

newDateTime and new DateTime difference, if any

In India, the common date format is

. So I input into the
in Indian format and with the code posted in one of Stack Overflow sites, I am converting
to the format of
format to further management of the string to find difference between two dates.

Though this code taken from Stack Overflow works fine with my needs, I am at a loss to understand the difference between
new DateTime
. Would anyone of you please explain? I appreciate the help.

DateTime d1;
if (DateTime.TryParse(textBox1.Text, out d1))
string newDateTime = d1.ToString("yyyy/MM/dd hh:mmtt");

Ben Ben

The DateTime is a constructor that (in this case) attempts to create a specified date format from a string. In it's simplest structure, it is declared like this:

DateTime d1 = new DateTime (int, int, int);

You then have a string which is a variable, with the name newDateTime. This is simply a string, which holds a collection of characters.

You can format a string, as you have done in your example, which would rely on the data being passed in to have some form of structure. However, once the information has been passed in, it is just a string.