Tag Archives: datetime

Loading DataTable from Excel: Unable to cast object of type 'System.DateTime' to type 'System.String'

Questions: I am trying to create a Datatable reading an excel file, which has a DateTime Column,rest all other columns are string. When trying to convert the DateTime column to Datetime Datatype ,I get an exception “Unable to cast object of type ‘System.DateTime’ to type ‘System.String’.” Could someone please guide me how do I resolve… Read More »

Split datetime of api response

Questions: I’m getting info from an API, and what I want to do is get the response of date time. This is part of my code: function perDetail(){ $http.get(‘/api/values’) .then(function(data){ $scope.details = data.data.Response; }); } Part of what i get is: “Date”:”2018-07-16T18:00:00″ And what I wanna do is get the hour: 18:00 Someone can guide… Read More »

Complex Linq Query Update as DateTime

Questions: There are A and B tables that are related to each other. I want to create a linq query that will update the Status value in the A table if the entire row of relationship lines with the AID column in the B table is equal to or smaller than today’s date in the… Read More »

Manipulation of XML Attribute datetime

Questions: I can serialize XML string. But I can’t create XML attribute for datetime like this <StartDate xsi:type=xsd:dateTime>datevalue</StartDate> I am using the c# class to represent the XML elements. I can’t produce the xsi:type attribute. I want to create it programmatically, how can I do that? Answers:

Supporting multiple custom DateTime formats when deserializing with Json.Net

Questions: I want to support deserializing more than one custom DateTime format with the Newtonsoft Json deserializer, so I am using IsoDateTimeConverter: var serializeSettings = new JsonSerializerSettings(); serializeSettings.Converters.Add(new IsoDateTimeConverter() { DateTimeFormat = “yyyyMMddTHHmmssZ” }); As the DateTimeFormat property does not accept an array of formats, I tried the following to support multiple custom date formats:… Read More »

ormlite query using datetime by eq()

Questions: I want to update datetime is equal. Here are my case. selet object. this object has updatedate field – datatime call web api update sync status field of (1) if updatedate is same. This is for preventing overwrite after another task’s update during http call. Here is my code. Apply.java public Date getUpdateDate() {… Read More »

System.FormatException: String was not recognized as a valid DateTime – when trying to convert MM/DD/YYYY

Questions: I have following C# method: DateTime ConvertStringToDate(string dateInString) { try { //string SSD = dateInString; //DateTime date = Convert.ToDateTime(SSD); //string strDate = String.Format(“{0:yyyy-MM-dd HH:mm:ss.fff}”, date); //return Convert.ToDateTime(strDate); return DateTime.ParseExact(dateInString, “MM/dd/yyyy”, CultureInfo.InvariantCulture); } catch (Exception) { } return DateTime.Today; } The code in comment is another way I tried before. I am in India and… Read More »

TimeZoneInfo.ConvertTimeFromUtc returned wrong DateTime

Questions: I called method: TimeZoneInfo.ConvertTimeFromUtc(DateTime.Now.ToUniversalTime(), TimeZoneInfo.FindSystemTimeZoneById(“GMT Standard Time”)) // UTC+0 It is returned DateTime for one hour larger than the correct DateTime. Why? How will it fix? Returned value should be equal DateTime.Now.ToUniversalTime() Answers: