Posts

Showing posts with the label datetime

Can you round a .NET TimeSpan object?

Can you round a .NET TimeSpan object? Can you round a .NET TimeSpan object? TimeSpan I have a Timespan value of: 00:00:00.6193789 Timespan Is there a simple way to keep it a TimeSpan object but round it to something like 00:00:00.62? TimeSpan Just a warning to others. I was going down the road of using TimeSpan as a public property off of a business object. Didn't realize that TimeSpan was not a "XmlSerializable" data type. Discussion on the issue: devnewsgroups.net/group/microsoft.public.dotnet.framework/… – BuddyJoe Dec 4 '08 at 0:14 11 Answers 11 Sorry, guys, but both the question and the popular answer so far are wrong :-) The question is wrong because Tyndall asks for a way to round but shows an example of truncation . Will D...

Subtract n months from a date field in hive

Subtract n months from a date field in hive I am trying to limit a table by a specific number of months, 24 for example in my WHERE clause. I have used the following with no success: Where month(EVENT_START_DT_TM) > add_months(from_unixtime(unix_timestamp()),-1) EVENT_START_DT_TM is a true datetime field and I want to have a 24 month look back period from the current date matching up against that field. Looking at the HIVE manual, a lot of date functions require date STRINGS, but what a true DATE field? 1 Answer 1 use Current_date() and add_months() function to get date before 24 months then use date_format() function to change the format as per your needs(matches to EVENT_START_DT_TM field format) hive> select date_format(add_months(current_date(),-24),"yyyy-MM-dd HH:mm:ss.SSS"); +--------------------------+--+ | _c0 | +--------------------------+--+ | 2016...

C# Method to Compare DateTime Fields Specified During Execution?

C# Method to Compare DateTime Fields Specified During Execution? My project has many objects with date fields, and I often need to select everything where one such field is within a date range. For example: public class Contract { public DateTime SignDate { get; set; } public DateTime ReleaseDate { get; set; } } public class PersonalCheck { public DateTime SignDate { get; set; } public DateTime ProcessDate { get; set; } public DateTime VoidDate { get; set; } } If I only cared about SignDate, it would be easy. I would declare an Interface... public interface IObjectWithSignDate { DateTime SignDate { get; set; } } ...change my other objects to inherit from it, then create a method like this: public static IQueryable<T> SignedWithin<T>(this IQueryable<T> items, DateTime start, DateTime end) where T : IObjectWithSignDate { return items.Where(q => q.SignDate >= start && q.SignDate <= end); } How can I avoid rewr...

Convert specific BigInt to DateTime in T-SQL

Convert specific BigInt to DateTime in T-SQL I have bigInt: 635307578922100000 which I need to convert to DateTime . 635307578922100000 DateTime I've tried few ways to do this: SELECT DATEADD(S, CONVERT(bigint,635307578922100000) / 1000, CONVERT(DATETIME, '1-1-1970 00:00:00')) and: SELECT DATEADD(ms, 635307578922100000 / 86400000, (635307578922100000 / 86400000) +25567) While I found the codes above work with bigInts like: 1283174502729 , with my bigInt I get the following error: bigInts 1283174502729 Msg 8115 ... Arithmetic overflow error converting expression to data type datetime. Does anyone have any idea how to solve it? What would be your expected result for the given input '635307578922100000' – StackUser Jul 26 '16 at 8:12 It looks like these are ticks. Possible dupli...