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
MedtronicVascSRAsked:
Who is Participating?
 
MedtronicVascSRConnect With a Mentor Author Commented:
Hi,
While I didn't figure out where the slashes came from I did solve my issue by rewriting the code to store the date in a string instead of DateTime before inserting into the Db.

string CreatedDateTime = DateTime.Now.ToString("M-d-yyyy h:mm:ss tt");

Cheers,
Ty
0
 
käµfm³d 👽Commented:
How are you viewing this data?
0
 
MedtronicVascSRAuthor Commented:
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
0
 
MedtronicVascSRAuthor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.