0

i have linq query i want to convert the entrance date in the select new linq query, this is the query:

   var query = (from con in db.Containers
                         join v in db.Vehicles on con.cont_vehicleid equals v.vehl_VehicleID
                         join cust in db.Custom_Captions on v.vehl_state equals cust.Capt_Code
                         where cust.Capt_Family == "vehl_state" && v.vehl_state!= "Incoming" && v.vehl_Deleted == null && con.cont_Deleted == null && v.vehl_ClearanceCompany == p.pusr_CompanyId
                         select new
                         {
                             cont_name = con.cont_Name,
                             vehl_Name = v.vehl_Name,
                             VehicleState = cust.Capt_AR,
                             vehl_drivername = v.vehl_drivername,
                             vehl_entrancedate = v.vehl_entrancedate,
                             vehl_customsdec = v.vehl_customsdec,
                             cont_rampid = v.vehl_rampid
                         }
                   );

how to convert the:

vehl_entrancedate = v.vehl_entrancedate,

as 24 hour??

the output form the previous code:

enter image description here

But,i want to display with 24 hour and without AM/PM like this :9/26/2016 11:55:58

or if the the time is 4:00 PM it will display 16:00

Note that the entrancedate field is type of datetime in database.

Fares Ayyad
  • 383
  • 1
  • 3
  • 18
  • what? how is a `date` different from a `24 hour date`? Date implies only the date portion, not the time. If you're actually working with a `datetime`, then there is no "format" a datetime is a datetime is a datetime. If you need to change its format for display, use an appropriate date format with `ToString` – Kritner Nov 28 '16 at 17:29
  • 2
    Do you need a date in 24 hours string format? Use ToString("HH:MM:ss") – celerno Nov 28 '16 at 17:31
  • @Kritner I have update the question – Fares Ayyad Nov 28 '16 at 17:32
  • @celerno could you give me an explanation because it gives me an overloaded error – Fares Ayyad Nov 28 '16 at 17:38
  • 1
    Possible duplicate of [C# DateTime to "YYYYMMDDHHMMSS" format](http://stackoverflow.com/questions/3025361/c-sharp-datetime-to-yyyymmddhhmmss-format) – Kritner Nov 28 '16 at 17:38
  • 3
    You haven't given enough information Fares. For example, what `type` is `vehl_entrancedate`? Is it a `DateTime`? `DateTime`s have no "format" they are already `DateTimes`, and have all of the information in them to represent that date in any format you'd like. It is unclear what problem you're actually having. Is it a display/ui issue? You say you want to display it in a specific way, it's just `vehl_entrancedate.ToString("yyyy/MM/dd HH:mm:ss");` assuming that `vehl_entrancedate` is already a `datetime` – Kritner Nov 28 '16 at 17:43
  • @Kritner i update the question. – Fares Ayyad Nov 28 '16 at 18:14
  • @Kritner when i vehl_entrancedate.ToString("yyyy/MM/dd HH:mm:ss"); it givevs me an error no overload for method 'ToString' takes 1 argument – Fares Ayyad Nov 28 '16 at 18:19
  • @Nkosi in database it's datetime – Fares Ayyad Nov 28 '16 at 18:20
  • @FaresAyyad is your model class a `DateTime` or is it a `DateTime?`? Is your DB columns a nullable `DateTime`? – Kritner Nov 28 '16 at 19:12
  • Try this vehl_entrancedate = v.vehl_entrancedate.Value.ToString("yyyy/MM/dd HH:mm:ss"); – Seano666 Nov 28 '16 at 21:25

1 Answers1

1

i got it like that :

<td style="width:125px;"><%#Eval("vehl_entrancedate") == null ? "" : ((DateTime)Eval("vehl_entrancedate")).ToString("dd/MM/yyyy HH:mm") %></td>
Fares Ayyad
  • 383
  • 1
  • 3
  • 18