My out put
Date :
11-09-2023 00:00:00
------------------------------------------------------
Actual need to 11-09-2023
My out put
Date :
11-09-2023 00:00:00
------------------------------------------------------
Actual need to 11-09-2023
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ziggy RafiqPosted Sep 11, 2023, 5:59 PM
In a Razor view
Replace myDate with the DateTime variable that holds the date we want to display.
@{
DateTime myDate = DateTime.Now; // Replace this with your date variable
string formattedDate = yourDate.ToString("dd/MM/yyyy");
}
In a C# code-behind file like in a controller
Replace myDate with the DateTime variable containing the date we want to display.
Using the "dd/MM/yyyy" format specifier in the ToString method ensures that the date is displayed in the desired "dd/MM/YYYY" format.
using System;
public IActionResult MyAction()
{
DateTime myDate = DateTime.Now; // Replace this with your date variable
string formattedDate = yourDate.ToString("dd/MM/yyyy");
ViewBag.FormattedDate = formattedDate;
return View();
}
Then, in your Razor view, we can access the formattedDate using ViewBag
Mithun PradhanPosted Sep 11, 2023, 1:16 PM
this is working
Mithun PradhanPosted Sep 11, 2023, 12:55 PM
my class
---------------------
public class test
{
public DateTime? UploadDate { get; set; }
}
Error:
No overload for method 'ToString' takes 1 arguments
Amit MohantyPosted Sep 11, 2023, 12:23 PM
Assuming you have a DateTime variable named
dateValuethat you want to format: