string date = "23/12/2017";
DateTime dt = DateTime.ParseExact(
date,
"dd/MM/yyyy hh:mm:ss tt",
CultureInfo.InvariantCulture);
but in dt
it's giving me 12/23/2017 12:00:00 AM
what approach do I have to use to convert this string to dd/mm/yyyy
with current time, as if i run this code at 03:20 PM
i want "23/12/2017 03:20:00 PM"
in my dt
object
I have an ASP.NET MVC action that accepts a date as a string and saves it to a a database table, in a field whose type is DATE.
I'm saving my dt object in it. i want to save my date in it as DD/MM/YYYY so i don't need to change its order. Right now dt object is in MM/DD/YYYY format. so when i explore my table data, it shows me data(dates) in MM/DD/YYYY order. i want to order my dt object as DD/MM/YYYY to it saves in table as DD/MM/YYYY so whenever I get value from my table I don't have to change order
/// asp.net Entities link to create connection with DataBase
private DatabaseEntities db = new DatabaseEntities();
//// Method to Save date in database
public ActionResult SaveDate(string date){
var DateTableObject = new Date();
DateTime dt = DateTime.ParseExact(date, "dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture).Add(DateTime.Now.TimeOfDay);
DateTableObject.Date = dt;
db.Date.add(DateTableObject);
db.SaveChanges();
}
//// Model class
public class Date{
public DateTime Date {set; get;}
}
/// Method to get dates
public ActionResult GetDates(){
return View(db.Date.tolist());
}
In view I'm receiving dates in MM/DD/YYYY format