Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing only Date from controller through DateTime Object. Trying Multiple ways bind Time alongwith

My .cs file contains this.

enter image description here

Model also contains the same datatype

while filling data in form i get the value as

enter image description here

In SQL i've kept datatype as date and in model it is necessary to keep DateTime.

I tried ParseExact(), .Date, etc but everything ultimately turns out along with time.

enter image description here

Can anyone please help? I tried many solutions found in this site related to this question but didn't get any help.

thank you in advance.

like image 789
Divya Avatar asked Jul 16 '26 16:07

Divya


1 Answers

Add this to your Model

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]

and in the .cshtml

@Html.TextBoxFor(m => m.LastPaymentDate, "{0:dd/MM/yyyy}")
like image 76
Arijit Mukherjee Avatar answered Jul 19 '26 07:07

Arijit Mukherjee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!