How do you get the current time (not date AND time)?
Example: 5:42:12 PM
Current time with AM/PM designator:
DateTime.Now.ToString("hh:mm:ss tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
DateTime.Now.ToString("hh:mm:ss.fff tt", System.Globalization.DateTimeFormatInfo.InvariantInfo)
Current time using 0-23 hour notation:
DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo)
DateTime.Now.ToString("HH:mm:ss.fff", System.Globalization.DateTimeFormatInfo.InvariantInfo)
Datetime.TimeOfDay
returns a TimeSpan
and might be what you are looking for.
MyEmail.Body = string.Format("The validation is done at {0:HH:mm:ss} Hrs.",DateTime.Now);
Can Use {0:HH:mm:ss}
, {0:HH:mm:ss.fff}
, {0:DD/mm/yyy HH:mm:ss}
, etc...
Use the code below
DateTime.Now.ToString("h:mm:ss tt")
Try this one. Its working for me in 3tier Architecture Web Application.
"'" + DateTime.Now.ToString() + "'"
Please remember the Single Quotes in the insert Query.
For example:
string Command = @"Insert Into CONFIG_USERS(smallint_empID,smallint_userID,str_username,str_pwd,str_secquestion,str_secanswer,tinyint_roleID,str_phone,str_email,Dt_createdOn,Dt_modifiedOn) values ("
+ u.Employees + ","
+ u.UserID + ",'"
+ u.Username + "','"
+ u.GetPassword() + "','"
+ u.SecQ + "','"
+ u.SecA + "',"
+ u.RoleID + ",'"
+ u.Phone + "','"
+ u.Email + "','"
+ DateTime.Now.ToString() + "','"
+ DateTime.Now.ToString() + "')";
The DateTime
insertion at the end of the line.
Try this:
DateTime.Now.ToString("HH:mm:ss tt")
For other formats, you can check this site: C# DateTime Format