w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Why Nullable<​DateTime> can be assigned to a paramter which only can be implict converted from DateTime?
Good question. What you dexcribe is this: class MyClass { public static implicit operator MyClass(DateTime date) { return new MyClass (); } } That's an implicit user-defined conversion from a non-nullable value type (here DateTime) to the class type, a reference type. Then a conversion DateTime→MyClass "induces" a conversion DateTime?→MyClass as it seems. With the above example, this compiles: DateTime? nullableDateTime = XXX; MyClass myClass = nullableDateTime; // implicit conversion from nullable! I tried to read carefully the part of the C# Language Specification beginning with: User-defined implicit conversions A user-defined implicit conversion from type S to type T is processed as follows: [...] Here the source S is DateTime?, and the t

Categories : C#

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

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

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

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#

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

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

format string in datetime c# to insert in MYSQL datetime column
Your line: string time = Convert.ToDateTime("10-10-2014 15:00:00"); Shouldn't compile. I can only guess that you don't have DateTime as type of your column in SQL Server, you should modify it to keep DateTime and then pass a DateTime type object, not a string.

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

Facebook OpenGraph DateTime attribute with only date being parsed as DateTime
Can I force Facebook to parse it as a date? That’s what its seems to be doing right now, but it does not seem to be what you want. I think what Facebook docs call the Precise-time format might be what you should rather use: Precise-time (e.g., '2012-07-04T19:00:00-0700'): events that start at a particular point in time, in a specific offset from UTC. This is the way new Facebook events keep track of time, and allows users to view events in different timezones. Which formats you can use to specify the OG DateTime type you can see here, https://developers.facebook.com/docs/opengraph/property-types/#simple

Categories : Facebook

Getting "TypeError: must be string, not datetime.datetime" in Jinja2 template but I'm using strftime
The problem is that utcnow() returns a datetime.datetime object, not a string. If you check the line number in the exception, it’s likely the strptime call that’s failing—it can parse a string into a date, but it can’t parse a date. Example: #!/usr/bin/env python2.7 import datetime import jinja2 def format_isodate(timestamp): """Format a ISODate time stamp for display.""" date = datetime.datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S.%f") return date.strftime('%Y-%m-%d @ %H:%M:%S') e = jinja2.Environment() e.filters['isodateformat'] = format_isodate t = e.from_string('{{ change.submit_date|isodateformat }}') print t.render(change={'submit_date': "2013-07-04 20:06:05.088000"}) print t.render(change={'submit_date': datetime.datetime.now()}) The first print of a

Categories : Python

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#

Rails Postgres - Datetime value won't save into Datetime column
Try putting these in the create method: logger.error params[:special_deal].class logger.error params[:special_deal].to_datetime or use the debugger to investigate them. It seems that it doesn't get converted properly to datetime. You will get a clear hint after this.

Categories : Ruby On Rails

Adding date or time in datetime format to another datetime
*This is a method using DateTime:* $begin = new DateTime($start); $finish = new DateTime($end); $difference = $finish->format('U') - $begin->format('U'); // working version $minutesDiff = round(($difference/60), 0); $finalDate = new DateTime(); $finalDate->modify(sprintf('+%s minutes', $minutesDiff)); edit added missing bracket edit2 version without ->diff() method

Categories : PHP

jQuery datetime to_string (iOS html5 datetime picker)
Finally got it working! This is how i did it: http://jsfiddle.net/h4tFz/ Date.prototype.format = function(format) //author: meizz { var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(), //minute "s+" : this.getSeconds(), //second "q+" : Math.floor((this.getMonth()+3)/3), //quarter "S" : this.getMilliseconds() //millisecond } if(/(y+)/.test(format)) format=format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); for(var k in o)if(new RegExp("("+ k +")").test(format)) format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k])

Categories : Javascript

String was not recognized as a valid DateTime when converting to DateTime
The problem you are having most likely links to formatting issues. Since DateTime has a lot of different ways it can be formatted, the Convert.ToDateTime( ... ) is probably using a format that is different from your hourminute format. Try using DateTime.Parse DateTime.TryParse DateTime.ParseExact See: Convert.ToDateTime DateTime.Parse DateTime.ParseExact .NET DateTime.Parse Parse string to DateTime in C# See Custom Date and Time Format Strings for formatting strings

Categories : C#

Sql query for CONVERT datetime to a different datetime Format in SQL 2005?
http://msdn.microsoft.com/en-us/library/ms187928.aspx check out see Microsoft's explanation on date formats the one you're looking for is 20 or 120 BTW, you should supply with varchar with a number like this varchar(10)

Categories : SQL

Nullable DateTime with SQLDataReader
replace DateTime startingDate; with DateTime? startingDate; The question mark marks it as a nullable value and your reader should be able to set startingdate to null instead of throwing an exception. you could also check for null values while your reader is working and replace null values with empty strings while(reader.read()) { //column is an int value of your column. I.e: if the column ist the 8th column, set column to 7 (0-based) StartingDate = (reader.IsDBNull(column)) ? null : reader.GetOrdinal("STARTINGDATE")); //instead of null you could also return a specific date like 1.1.1900 or String.Empty }

Categories : C#

DisplayFormat not working with Nullable
If I understood your intentions correct (I hope I did), then you can have a display template for Nullable by placing your template in Views/Shared/DisplayTemplates/Name.cshtml and define it like the following: @model System.DateTime? @Html.Label("", Model.HasValue ? Model.Value.ToString("MM/dd/yy hh:mm tt") : string.Empty) I hope this helps. EDIT You can have multiple Display Templates for the same type and specify which one to use by name so let's say you have: Views/Shared/DisplayTemplates/Name1.cshtml Views/Shared/DisplayTemplates/Name2.cshtml You can then call them like: @Html.DisplayFor(model => model.LastModifiedDateTime, "Name1") @Html.DisplayFor(model => model.LastModifiedDateTime, "Name2")

Categories : C#

Add nullable datetime column to Primary Key
try this: ALTER TABLE tblClauses_PolicyCategory ALTER COLUMN [ExpiryDate] SMALLDATETIME NOT NULL ALTER TABLE tblClauses_PolicyCategory ADD CONSTRAINT cons_expiryDate DEFAULT '2079-06-06' FOR ExpiryDate Before execute these lines, please check if exists some rows with ExpiryDate null, if yes, please, update all nullable rows to default value

Categories : SQL

convert from datetime to another locale datetime in java
if both have correct time and time zone, Date in milliseconds will be same for both server and client, no matter in what time zone they are . Send the date from client in milliseconds and accept it on serverside in a java.sql.Date(long) constructor. You mentioned javascript in tags. So Date can be sent through javascript using new Date(); and can be accepted by server using new java.sql.Date(client_date); In milliseconds, the client time would be converted to appropriate server time. If client time is not properly set, for that, you can use the time difference in milliseconds like - long time_difference= new Date()-new Date(client_date); long server_time_of_execution=new Date(Client_date_to_execute).getTime()+time_difference;

Categories : Java

displaying & editing datetime / datetime-tz in ember
datetime-tz is not a valid input type. http://www.w3.org/TR/html-markup/input.html The way that datetime-local is styled is not part of the spec and is left up to the browser. You might want to use something like the jQueryUI datepicker to ensure that things work the same across browsers. In that case you could extend the Ember.TextField view to handle setting up and tearing down the datepicker widget. App.DatePicker = Ember.TextField.extend({ didInsertElement : function(){ this.$().datepicker(); }, willDestroyElement : function(){ this.$().datepicker('destroy'); } }); {{view App.DatePicker valueBinding="date"}} Here's a JSBin : http://jsbin.com/ucanam/1054/edit

Categories : Ember Js

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 convert .NET DateTime.Ticks value into DateTime in SQL Query?
See this answer: Declare @TickValue bigint Declare @Days float Set @TickValue = 634024345696365272 Select @Days = @TickValue * POWER(10.00000000000,-7) / 60 / 60 / 24 Select DATEADD(d, Cast(@Days As int), Cast('0001-01-01' As DATE)) + Cast( (@Days - FLOOR(@Days)) As DateTime)

Categories : SQL

Asp.net MVC nullable DateTime model state validation
you are doing the client side validation, then you dont worry about that validation if the birth date value is null or empty then you returns null. public class DateFieldAttribute : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (value == null || value == string.empty) { return null; } else { //Validate the Birth date. } } } If you return NULL then the Modelstate doesn't consider Birthdate field.

Categories : Asp Net Mvc

Entity Framework: nullable DateTime toString(format) in vb.net handling
If you do a small experiment, you would understand perfectly what is happening: Dim normalDate As Date = Now Dim nullableDate As Nullable(Of Date) = normalDate Dim normalToText As String = normalDate.ToString("dd/MM/yy") 'Works perfectly Dim nullableToText As String = nullableDate.ToString("dd/MM/yy") 'Error The content in both variables, normalDate and nullableDate, is identical but they are not: the ToString("date in certain format") functionality expects a Date type as input; what you are sending is a modified version of the Date type (not too different, but not the same either). With CDate what you are doing is converting the modified version of Date into an actually valid Date type and thus the ToString() functionality works without any problem. Are you doing the right thing? Ye

Categories : Vb.Net

DateTime to XML format but keep the datatype as datetime
The dateTime object holds the date and time in a way that is independent of any formatting. The output format is chosen when you convert the value to a string. If it comes out as dd:mm:yyyy, that's because it's defaulting to the format used by the country/language configured for your machine. So the answer is, if you want the ISO format (which you refer to as XML format), then the time to request this is at the time you output the dateTime as XML; it's not a property of the date/time value itself.

Categories : C#

Convert a C# DateTime to XML dateTime type
You use Z to indicate UTC. Is this your problem? You can read more about it here: http://www.w3.org/TR/xmlschema-2/#dateTime-timezones So, 2002-10-10T07:00:00Z is 10 October 2002 at 0700 UTC.

Categories : C#

Finding the difference between a DateTime and a DateTime
You could check the HasValue property of the nullable date time, and then compare the Value property (in this case a DateTime) with the DueDate: IssuedBooks = (from transaction in db.BookTransaction join tag in db.BookTagMaster on transaction.BookTagID equals tag.ID where tag.IsTagActive == true join book in db.BookMaster on tag.BookID equals book.ID join author in db.AuthorMaster on book.AuthorID equals author.ID join category in db.CategoryMaster on book.CategoryID equals category.ID join publisher in db.PublisherMaster on book.PublisherID equals publisher.ID select new BookIssuedView { ID = transaction.ID, EmployeeName = transaction.EmployeeName, IssuedDate = transaction.IssuedDate, ReturnDate = transaction.ReturnDate, BookName = book.Name, AuthorName = author.N

Categories : C#

ndb is not accepting a monkeypatched datetime.DateTime
The issue is caused by however monkey patch is working. The value is validated by checking isinstance: def _validate(self, value): if not isinstance(value, datetime.datetime): raise datastore_errors.BadValueError('Expected datetime, got %r' % (value,)) So if it was a true subclass, isinstance would work just fine, e.g. >>> class A(object): pass >>> class B(A): pass >>> b = B() >>> isinstance(b, A) True You likely don't need to use monkeypatch at all here. Instead you can create your own custom datetime.datetime subclass at the toplevel and then just use that instead of manually using datetime.datetime.

Categories : Python

Join tables by t1.datetime and MAX(t2.datetime)
If I understood your question correctly, you need to join the whole Table2 to every row of Table 1, where Table1.timestamp > Max(Table2.timestamp)? Well, the below query should do the trick, but may be you need to clarify the question. Select * from Table1 t1, Table2 t2 Where t1.timestamp > (select MAX(t3.timestamp) from Table2 t3)

Categories : SQL

SQLAlchemy DateTime to datetime.datetime
First of all, notice that datetime.timedelta does not take 'months' as an argument. Try it with 'weeks=8' instead (http://docs.python.org/2/library/datetime.html#datetime.timedelta). Second, use 'filter' rather than 'filter_by' as the latter is for simpler queries involving queries by value (i.e. User.name='Bob' http://docs.sqlalchemy.org/en/rel_0_8/orm/query.html#sqlalchemy.orm.query.Query.filter). So, what I would write would look like this: candidates = session.query(User).filter((User.time - datetime.datetime.utcnow()) > datetime.timedelta(weeks=8)) And finally, what is the mapping of your 'User' table, maybe the problem is with the Columns definitions?

Categories : Python

Django ORM: using extra to order models by max(datetime field, max(datetime field of related items))
Your join is wrong. It should be: maps_map join maps_mapitem on maps_map.id = maps_mapitem.map_id As it stands you're forcing the PKs to be equal, not the map's PK to match the items' FKs. edit I suspect your subquery isn't joining against the main maps_map part of the query. I am sure there are other ways to do this, but this should work: Map.objects.extra(select={ "last_updated": "greatest(modified_date, (select max(maps_mapitem.modified_date) from maps_mapitem where maps_mapitem.map_id = maps_map.id))"})

Categories : Mysql

How to cast datetime to datetimeoffset?
To convert from a local time to a datetimeoffset with the current time offset seems to take some trickery. There's probably a simpler way, but this seems to do it; SELECT ChangeDate, CONVERT(DATETIMEOFFSET, CONVERT(VARCHAR, ChangeDate, 120) + RIGHT(CONVERT(VARCHAR, SYSDATETIMEOFFSET(), 120), 6), 120) FROM AuditLog; It's probably worth creating a function; CREATE FUNCTION LOCALIFY(@dt DATETIME) RETURNS DATETIMEOFFSET AS BEGIN RETURN CONVERT(DATETIMEOFFSET, CONVERT(VARCHAR, @dt, 120) + RIGHT(CONVERT(VARCHAR, SYSDATETIMEOFFSET(), 120), 6), 120) END; ...and then just... SELECT ChangeDate, dbo.LOCALIFY(ChangeDate) FROM AuditLog;

Categories : Sql Server

Explicit date/datetime cast
Look at simple example (MySql 5.6): drop table dattes; create table dattes( id int, da_te date, name varchar(200) ); set @x = 0; insert into dattes select (@x:=@x+1), '2013-5-1' + interval @x day, t.column_name from information_schema.columns t ; and here is a query: Set @start_date = cast( '2013-5-2' as date); Set @start_datetime = cast( '2013-5-2 15:00' as datetime); Set @end_date = cast( '2013-5-10' as date); select (Select sum( id ) from dattes where da_te between @start_date and @end_date) da_test1, (Select sum( id ) from dattes where da_te between @start_datetime and @end_date) da_test2, (Select sum( id ) from dattes where da_te between cast( @start_datetime as date) and @end_date) da_

Categories : Mysql

sql convert/cast varchar(255) to datetime
Well, considering the consistency of the data (i.e. it's extremely well known), you can do this: SELECT CONVERT(DATETIME, SUBSTRING('05/21/2013 00:00:00.000000', 1, LEN('05/21/2013 00:00:00.000000') - 3), 120) because the issue is simply the precision. So more specifically, you'd want: SELECT CONVERT(DATETIME, SUBSTRING(startDate, 1, LEN(startDate) - 3), 120)

Categories : SQL

How to cast the interval of DateDiff function of the SQL in to Datetime data type
As pointed out in the comments DATEDIFF returns an INT value of the difference of both dates. Since DATETIME is based on 1900-01-01 being the "base date" meaning assinging 0 to a DATETIME will result in the value 1900-01-01, you can add your date difference to that and get a value relative to that point in time (1900-01-01). Here is an example: DECLARE @date1 DATETIME = GETUTCDATE() DECLARE @date2 DATETIME = DATEADD(DAY, -1, GETUTCDATE()) DECLARE @zeroDate DATETIME = 0 SELECT DATEADD(SECOND, DATEDIFF(SECOND, @date1, @date2), @zeroDate) I also set up an SQLFiddle where you can try that out.

Categories : SQL

AM/PM Distinction when formatting datetime field from sqlite into datetime field in R
This seems to work, using the formats listed in ?strptime: test <- c("2013-07-08 01:06:02 AM", "2013-07-08 01:06:02 PM") as.POSIXct( test, format="%Y-%m-%d %I:%M:%S %p" ) Result: [1] "2013-07-08 01:06:02 EST" "2013-07-08 13:06:02 EST"

Categories : R

Merge two multidimensional arrays, but cant duplicate using datetime
If I'm correct you are trying to merge the arrays based in timestamps. Try out this fiddle var Array1 = [ ['a', 'b', '0000-00-00 00:00'], ['c', 'd', '0000-00-00 00:59'], ['e', 'f', '0000-00-00 00:10'] ]; var Array2 = [ ['z', 'x', '0000-00-00 00:00'], ['h', 's', '0000-00-00 00:49'], ['e', 'f', '0000-00-00 00:20'] ]; function mergeArrays(arr1, arr2) { var merger = {}; for (var i = 0; i < arr1.length; i++) { merger[arr1[i][2]] = [arr1[i][0], arr1[i][1], arr1[i][2]]; } for (var i = 0; i < arr2.length; i++) { if (!(arr2[i][2] in merger)) { merger[arr2[i][2]] = [arr2[i][0], arr2[i][1], arr2[i][2]]; } } var output = []; for (var key in merger) { output.push(merger[key]); } return out

Categories : Javascript

SQL server 2012: Cast a varchar (255) column to datetime results to an out-of-range value error
There are many string formats supported by SQL Server - see the MSDN Books Online on CAST and CONVERT. Most of those formats are dependent on what language / dateformat settings you have - therefore, these settings might work some times - and sometimes not. The way to solve this is to use the (slightly adapted) ISO-8601 date format that is supported by SQL Server - this format works always - regardless of your SQL Server language and dateformat settings. The ISO-8601 format is supported by SQL Server comes in two flavors: YYYYMMDD for just dates (no time portion); note here: no dashes!, that's very important! YYYY-MM-DD is NOT independent of the dateformat settings in your SQL Server and will NOT work in all situations! or: YYYY-MM-DDTHH:MM:SS for dates and times - note here: this

Categories : Sql Server



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