This topic is locked
[SOLVED]

 Format Datetime in email

11/27/2015 10:59:40 AM
ASPRunner.NET General questions
jadach authorDevClub member

How can I format the datetime field to not show time when emailing the value?
I am using SQL Server 2014. My email code is "Send simple email." My value is part of the string msg.
My datetime value is being passed like so: "+values["AppointmentDate"].ToString()+"
My result in the email is 2015-11-27 00:00:00.
My desired result would be either 11/27/2015 or better yet Friday, November 27, 2015.
Thanks

admin 12/1/2015

You can use something like this:

String.Format("{0:dddd, MMMM d, yyyy}", Convert.ToDateTime((string)values["AppointmentDate"]) )


Here are some formatting examples:

http://www.csharp-examples.net/string-format-datetime/

jadach authorDevClub member 12/7/2015

Thank you for the response. I am having difficulty adding this to the following. I cannot get the syntax right. Can you help?
I need to replace

+values["AppointmentDate"].ToString()+

with

String.Format("{0:dddd, MMMM d, yyyy}", Convert.ToDateTime((string)values["AppointmentDate"]) )

On this line:
string msg = "Appointment<br />"+values["AppointmentName"].ToString()+"<BR />Details<br />"+values["Details"].ToString()+"<br />"+values["AppointmentDate"].ToString()+"";

admin 12/8/2015

Try something like this:

string msg = "Appointment<br />"+values["AppointmentName"].ToString()+"<BR />Details<br />"+values["Details"].ToString()+"<br />"+String.Format("{0:dddd, MMMM d, yyyy}", Convert.ToDateTime((string)values["AppointmentDate"]) );
jadach authorDevClub member 12/9/2015

Thank you so much!!!

This is exactly why I love Xlinesoft. You guys are awesome and ALWAYS help.