MedtronicVascSR
asked on
DateTime.Now Returns Odd Format with C#
Hi,
I'm adding a feature to some existing code and for some reason when I grab the current date and time to stuff into the database I get a format that is odd to me.
this:
DateTime CreatedDateTime = DateTime.Now;
produces this:
10\/25\/2011 5:35:45 PM
I don't understand where the forward and backward slashes come from, and I've tried to replace them using String.Replace with no success.
Why would the format come back this way, and why can't I programmatically remove them?
Cheers,
Ty
I'm adding a feature to some existing code and for some reason when I grab the current date and time to stuff into the database I get a format that is odd to me.
this:
DateTime CreatedDateTime = DateTime.Now;
produces this:
10\/25\/2011 5:35:45 PM
I don't understand where the forward and backward slashes come from, and I've tried to replace them using String.Replace with no success.
Why would the format come back this way, and why can't I programmatically remove them?
Cheers,
Ty
How are you viewing this data?
ASKER
Hi,
In order to determine why the SQL insert statement wasn't working I outputed the SQL string in Fidler. Here's a truncated version of that SQL statement with the key info bolded. The current program requires that the date be generated from the code and inserted, and not auto-created from within the table at the time it's inserted (don't ask me why).
INSERT INTO PHYSICIAN_IN_SERVICE ( FIRST_NAME, MIDDLE_INITIAL, LAST_NAME, EMAIL_ADDRESS, PHYSICIAN_INFO_ID, ACCOUNT_NUMBER, CREATED_DATE) VALUES ( 'Ty', '', 'Strange', 'neo@trinity.com', 7777, '1209188', 10\/20\/2011 2:52:37 PM,
The code block I'm working with does reside within a web service that has been posted with Json data, but since the DateTime stamp is not from the HTTP post but rather being generated on it's own I'm don't think that's the issue.
Cheers,
Ty
In order to determine why the SQL insert statement wasn't working I outputed the SQL string in Fidler. Here's a truncated version of that SQL statement with the key info bolded. The current program requires that the date be generated from the code and inserted, and not auto-created from within the table at the time it's inserted (don't ask me why).
INSERT INTO PHYSICIAN_IN_SERVICE ( FIRST_NAME, MIDDLE_INITIAL, LAST_NAME, EMAIL_ADDRESS, PHYSICIAN_INFO_ID, ACCOUNT_NUMBER, CREATED_DATE) VALUES ( 'Ty', '', 'Strange', 'neo@trinity.com', 7777, '1209188', 10\/20\/2011 2:52:37 PM,
The code block I'm working with does reside within a web service that has been posted with Json data, but since the DateTime stamp is not from the HTTP post but rather being generated on it's own I'm don't think that's the issue.
Cheers,
Ty
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was able to solve my issue before others had a chance to post. As for the B grade it wasn't necessarily the only or best way to address the issue.