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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Sep 11, 2023, 8:23 AM EDT
Assuming you have a DateTime variable named
dateValuethat you want to format:Mithun Pradhan194 reputationPosted Sep 11, 2023, 8:55 AM EDT
my class
---------------------
public class test
{
public DateTime? UploadDate { get; set; }
}
Error:
No overload for method 'ToString' takes 1 arguments
Mithun Pradhan194 reputationPosted Sep 11, 2023, 9:16 AM EDT
this is working
Ziggy RafiqRank #100 · 21.3K reputationPosted Sep 11, 2023, 1:59 PM EDT
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