w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
implicit operator on types like DateTime without datetime-functions like ToShortDateString()
Add an extension method on AnnotationField<DateTime?> type: public static class Extensions { public static string ToShortDateString(this AnnotationField<DateTime?> item) { return item.Value.Value.ToShortDateString(); } } With that, you'll be able to call: public AnnotationField<DateTime?> Birthday { get; set; } myObject.Birthday.ToShortDateString();

Categories : C#

Nhibernate throws Object of type 'System.Linq.EnumerableQuery`1[Entity]' cannot be converted to type 'System.Linq.IQueryable`1[System.Object[]]'
.AsQueryable() will wrap the given IQueryable from NH needlessly into a new Queryable but since NH will by default use object arrays as results and transform it later it will fail casting. Also Selecting the user into another User will prevent changetracking and is needless copying. repo.GetAll().Where(f => f.Id == id).FirstOrDefault(); should be enough or even better because of the sessioncache usage var user = session.Get<User>(id); if (user == null) // user with given Id does not exist

Categories : C#

Comparing C# datetime value to SQL Server Compact 4 datetime
You should format the date to yyyyMMdd hh:mm:ss. lastDeliveryDate.toString("yyyyMMdd hh:mm:ss"). In this postare more details. How to compare sqlite TIMESTAMP values

Categories : C#

how to get system DateTime in webservice
From your error response, I assume that the problem is not in your code, but in the addressing of this method. You're probably trying to parse a string value into a DateTime format, somewhat like this: DateTime date = DateTime.Parse(dateAsString); If the dateAsString variable does not contain a valid date, then the ArgumentException you described will be thrown. You can resolve this by trying to find out what's wrong with the string date you're trying to parse. It could very well be an empty string that's causing the problem. To help you with finding the troublemaker, use DateTime.TryParse to throw a new Exception with some helpful information: DateTime date; if (!DateTime.TryParse(dateAsString, out date) { throw new Exception("Invalid date: " + dateAsString); }

Categories : Asp Net

create datetime irrespective of system date
The date/time is stored in a particular format regardless of the system locality. Only the the output is affected by the locality. Regardless of how it "looks" you can always change the output using the ToString method And the various formats You can even implement a global cultureinfo to apply which may be what you're looking for

Categories : C#

DateTime, an exception of type 'System.InvalidOperationException'
I am not an expert of Windows Phone, but it seems to me that the Value property of a TimePicker control is defined as DateTime? meaning a nullable DateTime. When you try to assign it to a DateTime variable (that cannot accept null values) and the TimePicker is null you get the InvalidOperationException You could try with startBreak1 = startBreak1.Value ?? DateTime.MinValue;

Categories : C#

Unable to cast object of type 'System.Linq.OrderedEnumerable`2[***]' to type 'System.Collections.Generic.IEnumerable`1[***]'
You're trying to convert a collection of DirectoryToken to a collection of Token. This is called a covariant conversion, and it's only supported in .Net 4.0 or later. If you can't upgrade, you can call .Cast<Token>() to create a new IEnumerable<T> instance (actually an iterator) that casts each object to the desired type. Under no circumstances do you need an explicit cast operation.

Categories : C#

How to solve System.DateTime does not contain a definition for TryParseExact" on Windows CE and C#
Checkout this explanation, it shows how to make your own tryparse, because compact framework does not have it's own. http://www.yortondotnet.com/2009/11/tryparse-for-compact-framework.html

Categories : C#

null reference in coded webtest with system.datetime
You define three arrays: public string[] SessionID; public string[] SessionTime; public string[] CreatedTime; But, they aren't initialized before you attempt to use them. Basically, you are doing this: string[] foo; foo[1] = "bar"; And you need to do this: string[] foo = new string[10]; // sized appropriately foo[1] = "bar";

Categories : C#

System.FormatException: String was not recognized as a valid DateTime
Try this if your Date's format is "yyyy/MM/dd": String[] date = typedDate.Text.Split(new char[] { '/' }); Datetime dy = new DateTime(int.Parse(date[0]), int.Parse(date[1]), int.Parse(date[2]));

Categories : C#

implicit conversion between '' and 'System.DateTime' error
Cast it to DateTime?: private DateTime? pApproveDate=null; pApproveDate =(Reader["ApproveDate"]==DBNull.Value)?(DateTime?)null: Convert.ToDateTime(Reader["ApproveDate"]);

Categories : C#

Issue to get current system datetime dynamically using windows service
The answer to this forum question says: If your Windows Service is running under the SYSTEM account or other account without a profile it will use the settings defined under the HKEY_USERS/.DEFAULT/Control Panel/International registry key. You can change these values from Control Panel / Regional and Language Options / Advanced by checking the check box Apply all settings to the current user account and to the default user profile. Also, read more about the issue on this similar question: Why is my CurrentCulture en-GB and my CurrentUICulture en-US.

Categories : C#

Property or indexer 'System.DateTime.TimeOfDay' cannot be assigned to — it is read only
You can only create new DateTime instances. According to your shown code, you want to set only the day time. This should do it: newStartDateGroup = DateTime.Today.Add(i.OpenTime); DateTime.Today is today at 00:00.

Categories : C#

Unable to convert MySQL date/time value to System.DateTime in VS2010
Set both of these configurations in your connection string. "Convert Zero Datetime=True" "Allow Zero Datetime=True" http://bugs.mysql.com/bug.php?id=26054 Please check manual under connect options and set "Allow Zero Datetime" to true, as on attached pictures, and the error will go away. Check this also: http://mdid.org/mdidwiki/index.php?title=Unable_to_convert_MySQL_date/time_value_to_System.DateTime_exception To fix this problem, either replace all invalid timestamps with NULL or a valid timestamp, or add Allow Zero Datetime=true

Categories : C#

Error converting value {null} to type 'System.DateTime' in input json
As the error is trying to tell you, .Net value types like DateTime cannot hold nulls. If you want to allow nulls, use nullable types: DateTime? StartDateFrom { get; set; }

Categories : C#

Convert datetime from xml to c# object using linq
use XElement to DateTime conversion instead of Convert.ToDateTime: XDocument xmldocument = XDocument.Load(xmlfile); List<Client> clients = (from client in xmldocument.Element("Clients").Elements("Client") select new Client { Name = (string)client.Element("Name"), Birthday = (DateTime)client.Element("Birthday") }).ToList();

Categories : C#

When comparing two equal integers in while loop, the equal-to operator fails?
You will want to use .equals() to compare the value of two objects. Anytime you use == it will compare instances of objects. .equals() is a method inherited from Object and is used to compare the values of objects.

Categories : Java

Why method now in Python is obtained as datetime.datetime.now instead of datetime.time.now?
"Now" is a point in time. That means date matters; if it's noon now, yesterday noon is not also now. (Time of day also matters; 9 AM today is also not now.) Thus, it makes sense to have a datetime.datetime.now, but not a datetime.time.now. It could make sense to have a datetime.time.currentlocaltime or datetime.time.currentutctime, but those methods don't exist. You could put in a feature request if you want.

Categories : Python

Specific linq exception when converting string to int. LINQ to Entities does not recognize the method 'Int32 ToInt32(System.Object)' m
You can easily fix this by first performing the conversion and then querying the database: public tblOpportunity GetOpportunityByCode( string clientCode, string opportunityCode) { tblOpportunity opportunity = null; var convertedOpportunityCode = Convert.ToInt32(opportunityCode); ConnectionHandler.Invoke<EntityConnection>((connection) => { var context = new xxEntities(); opportunity = context.tblOpportunities .FirstOrDefault(o => o.ClientCode == clientCode && o.OpportunityCode == convertedOpportunityCode); }); return opportunity; }

Categories : C#

Internal System.Linq.Set vs public System.Collections.Generic.HashSet
The implementation of this Set<T> is far simpler than HashSet<T> as it is only needs to add and remove elements and check for existence for LINQ internal processes. It does not implement any interfaces or expose iterators etc. So probably it is faster for the purpose LINQ uses it for.

Categories : C#

asp.net json web service sending array error Cannot convert object of type 'System.String' to type 'System.Collections.Generic.List`1[System.String]'
You need to make your data parameter of the $.ajax call like this: JSON.stringify({'a': variables}) The JSON variable is not available in < IE8 so you'll want to include a JSON implementation like the one mentioned in the answer here Also, you had an extra } in the success function. So, in the future, if you want to add extra parameters to your data object passed to the web service, you'd construct it like so: var someArr = ['el1', 'el2']; JSON.stringify({ 'param1': 1, 'param2': 'two' 'param3': someArr // etc }); JavaScript: var variables = Array(); var i = 0; $('#Div_AdSubmition').find('.selectBox').each(function () { variables[i] = $(this).find('.selected').find(".text").html(); i++; }); $.ajax({ type: 'post', data: JSON.stringify({'a': variables}),

Categories : C#

Linq - how to subtract current index DateTime item with previous index DateTime item
Query If you want to get the TimeSpans for each of the waiting periods between consecutive Flight Segments, you can use this: Flight flight = ...; IEnumerable<TimeSpan> query = flight.Segments .SelectPairs((a, b) => b.DepartureDate - a.ArrivalDate); For a Flight with N Segments, this will give you N - 1 TimeSpans. Edit: If you want to get the total amount of waiting time between all Segments on a Flight, you can augment the LINQ query like this: TimeSpan totalWaitingTime = flight.Segments .SelectPairs((a, b) => b.DepartureDate - a.ArrivalDate) .Aggregate(TimeSpan.Zero, (s, t) => s + t); Helper public static IEnumerable<TResult> SelectPairs( this IEnumerable<T> source, Func<T, T, TResult> selector) { var first = true; var pr

Categories : C#

Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Linq.IQueryable'
When you apply the When clause you use the type (cust, sa) => new { customer = cust, advice = sa }. But after you change to new { cust_id = g.Key.cust_id, cust_code = g.Key.cust_code, cust_name = g.Key.cust_name } They are different types to compiler.

Categories : C#

Rio fieldbinding: LINQ interface not supporterd error on Datetime in LINQ comparison?
The only things I can think that might be causing this are: If this is some kind of linker bug where Xamarin.Android is removing the comparable support for DateTime before deploying to the Android test device If this is some kind of compiler difference where Xamarin.Android is somehow picking up the base INotifyChange interface for Value which uses object instead of the INotifyChange<T> interface which uses new to override Value to type T. To test if it's the first, can you deploy in debug with the linker set to 'none' - does the problem still occur? If it's the first, then you can trick the linker into including this interface using a file like LinkerPleaseInclude. To test if it's the second, can you change your code to: mylist.Where(f => ((DateTime)f.LastSeen.Value

Categories : Android

Linq to Entities - "Unable to create a constant value of type 'System.Object'..."
I think it is the following line that causes the problems: Line = (p.ProdLine.Factory.Factory_No + '/' + p.ProdLine.ProdLine_No.ToString()) This is since it combines a query-result with a .NET method result. Maybe this will work. It delays the creation the of Line-variable-contents until after the query has been run. var query = (from p in Productions join t in MaterialTransactions on p.Prodn_ID equals t.Prodn_ID where p.WO_ID == 2345 orderby p.Date descending select new { Id = p.Prodn_ID, Date = p.Date, Line1 = p.ProdLine.Factory.Factory_No, Line2 = p.ProdLine.ProdLine_No, Qty = p.Qty, Wgt = (double)p.ActWgt, Speed = (double)p.ActSpeed, MaterialUsed = t.Material.Name }) .AsEnumerable() // This is where the db-stuff stops, and the in-memory stuff b

Categories : C#

Comparing DateTime Not Working
That could work in JavaScript, but in PHP it will not :P However, you could calculate an interval between dates. $interval = $date1->diff($date2); if ($interval->invert){ //1 if negative and 0 if positive // $date2 has a bigger time value } else { // $date1 has a bigger time value }

Categories : PHP

Error in comparing DateTime
The message The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. is pretty self explanatory. SQL won't know how to fetch Date property of a DateTime type. It can work with DateTime. It can work with Integers. In you case, you'll have to make it work with integers. As far as performance it concerned.. I don't see any bad impacts. PS:The support of Date datatype in SQL is not related to this.

Categories : C#

Comparing DateTime stamps in Msbuild
Try to use inline task: (msbuild v4+ is required, I guess) (I didn't tested it) <UsingTask TaskName="CompareDates" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)Microsoft.Build.Tasks.v4.0.dll" > <ParameterGroup> <FirstDate ParameterType="System.DateTime" Required="true" /> <SecondDate ParameterType="System.DateTime" Required="true" /> <Result ParameterType=" "System.Int32" Output="true" /> </ParameterGroup> <Task> <Using Namespace="System"/> <Code Type="Fragment" Language="cs"> <![CDATA[ Log.LogMessage("First Date: " + FirstDate, MessageImportance.High); Log.LogMessage("Second Date: " + SecondDate, MessageImportance.High); Result =

Categories : C#

Comparing DateTime fields with different 'times'
You could try using the Date property, which represents the current DateTime without any Time part: var q = gc.GraphicRequests.Where(a => a.DateInWork.Date == fromDate); If DateInWork is nullable (i.e. DateTime?), use this: var q = gc.GraphicRequests.Where(a => a.DateInWork.HasValue && a.DateInWork.Value.Date == fromDate); However, if you are using Entity Framework, you may need to look at the TruncateTime method: var q = gc.GraphicRequests.Where(a => EntityFunctions.TruncateTime(a.DateInWork).Value == fromDate);

Categories : C#

Comparing two Joda-Time DateTime objects
You're creating two DateTime instances probably representing the same instant in time, but with different time zones. Neither is before or after the other. The time zone just affects how the date/time methods like getHourOfDay() convert the instant in time.

Categories : Java

Why is the C# != operator comparing value types by reference?
When you do: (row1[fieldNames[i]] != row2[fieldNames[i]]) row[x] gives you an object see http://msdn.microsoft.com/en-us/library/146h6tk5.aspx If you compare objects with == you compare the reference. You have to cast to their primitive Datatype OR compare with obj.Equals(obj2) For Example: object a = 2; object b = 2; if (a == b) Debug.WriteLine("== = true"); if (a.Equals(b)) Debug.WriteLine("equals = true"); Debug Output: equals = true

Categories : C#

Converting DateTime to unix timestamp and back again - result is not equal
They aren't the same. Look at dateTime.Ticks and dateTimeConvertedBack.Ticks. This will work: DateTime dateTimeConvertedBack = ePoch.AddTicks(timeSpan.Ticks);

Categories : C#

Python Thread.start() throws weird exception relating to datetime.datetime
Your code doesn't show where timeout is coming from. It's not "suddenly becoming" anything. Whatever your code, at some point previously, a datetime.datetime was assigned to timeout. Either eliminate that condition, or handle it appropriately (perhaps by catching the exception). Update: You're modifying standard library code, which is an awful idea. Directly or indirectly, you're passing in a datetime.datetime. Use pdb to figure out where. Run your code in the python console. When you trigger the exception do import pdb; pdb.pm(), and you'll drop into the debugger at the site of the exception. You can explore from there.

Categories : Python

retrieve rows via join and datetime query where datetime is in past AND NOT in future
I think you need to have a group function. SELECT DISTINCT `users`.id FROM `users` LEFT OUTER JOIN `events` ON events.user_id = users.id LEFT OUTER JOIN `purchases` ON `purchases`.id = `events`.purchase_id WHERE events.starts_on <= '2013-07-15' or events.starts_on >= '2013-08-12' group by `users`.id having min(starts_on) <= '2013-07-15' and max(starts_on) < '2013-08-12' LIMIT 0, 30;

Categories : Mysql

CASTing a datetime to string if null value - keeping original datetime formatting
Replace cast with convert and appropriate style: Convert syntax & styles, eg: ISNULL(convert(varchar(20), fd.decision_date, 120), 'PENDING') as facility,

Categories : SQL

populating datetime value from php into Jquery Moble text input datetime-local
$(document).ready(function() { $("#datetime-1").val(<?php YOUR CODE ?>); $("#datetime-2").val(<?php YOUR CODE ?>); }); Its a bit hacky but it should work, just make sure the format of the date is what jq mobile is expecting.

Categories : PHP

Not valid datetime error due to wrong fomat of datetime in calender extender
Some Code to catch something like this and don't cause an Exeption: if (DateTime.TryParse(txtDate.Text, out dateValue)) { dr["Date"] = dateValue; } else { Debug.Write("TextBox Value '{0}' isn't a valid datetime.", txtDate.Text); }

Categories : C#

How to write not equal operator in linq to sql?
You need to revise the join to be on the related columns between the 2 tables, then you add your condition in the where clause, like the following: using (RapidWorkflowDataContext context = new RapidWorkflowDataContext()) { var query = from w in context.WorkflowInstances join c in context.Workflows on w.WorkflowID equals c.ID where EmpWorkflowIDs.Contains((int)w.ID) && w.CurrentStateID != c.LastStateID select w; return query.ToList(); }

Categories : C#

DateTime on Linq To Sql?
Because it's a nullable datetime you might have to do something like: <%= MyAppTable.MyDataField.Value.ToShortDateTime() %> Before doing that make sure it has a value though.

Categories : C#

MVC : Binding datetime value (bootstrap datetime picker) from view to model
You need to give the input tag a name that corresponds to a property in your model, like this: <input name="DateEntered" data-format="dd/MM/yyyy HH:mm:ss PP" type="text"/>

Categories : Asp Net Mvc



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.