datetimeoffset

Storing a c# DateTimeOffset value in a SQL Server 2005 database

I want to store a a c# DateTimeOffset value in a SQL Server 2005 database. Sql 2008 has this as a built-in-type, but SQL Server 2005 does not. The DateTimeOffset structure has a DateTime value wich I store as DateTime, an an Offset property (of type TimeSpan). Since this is the time zone relative to UTC, presumably it is usally at a wh...

When Would You Prefer DateTime Over DateTimeOffset

A few months ago I was introduced to the new DateTimeOffset type and was glad DateTime's flaws with regard to time zones were finally taken care of. However, I was left wondering if there were any overhead or problems that could occur from using this new type. I work on a multi-locale web application. Does anyone know of anything that ...

How to convert .NET DateTimeOffset ito Sql2008 DateTimeOffset

Hi folks, i'm not sure how to correctly format a .NET DateTimeOffset variable, as a string, for SqlServer 2008 to correct parse the value. currently, if i provide the default .ToString() value from a normal DateTimeOffset value, it errors. Here is a sample .ToString() value that errors (eg. Sql2008 doesn't like it): '25/12/2008 2:12:2...

How do I stop the DateTimeOffset scale from causing a ChangeConflictException in linq to Sql?

The following code tries to create a new record and then modify it after it has been committed to the database. The last SubmitChanges() call throws a ChangeConflictException. ItemA itemA = new ItemA(); itemA.Foo = "a"; itemA.Created = DateTimeOffset.Now.UtcDateTime; ItemAs.InsertOnSubmit(itemA); SubmitChanges(); itemA.Foo = "b"; Subm...

Determine Whether Daylight Savings Time (DST) is Active in Java for a Specified Date

I have a Java class that takes in the latitude/longitude of a location and returns the GMT offset when daylight savings time is on and off. I am looking for an easy way to determine in Java if the current date is in daylight savings time so I can apply the correct offset. Currently I am only performing this calculation for U.S. timezon...

DateTimeOffsetAdapter interfering with WCF serialization of DateTimeOffset objects

I have a WCF service reference (= client proxy) generated by Visual Studio 2008 (.net 3.5 sp1). The generated code contains a data contract with DateTimeOffset properties so naturally VS decorated it with KnowTypeAttribute(System.DateTimeOffset). Whenever I invoke a WCF operation that returns the above mentioned data contract, I get th...

Date increment

I want to take the next day by giving the current date The code i used as follows +(NSDate *)getForDays:(int)days fromDate:(NSDate *) date { NSTimeInterval secondsPerDay = 24 * 60 * 60 * days; return [date addTimeInterval:secondsPerDay]; } this works fine but when the daylight saving enabled this leads to errors. How can ...

Why does a datetimeoffset have 28 hours of timezones?

I am looking into using the datetimeoffset for SQL Server 2008. According to the MSDN article there is a time zone offset range of -14:00 through +14:00. I can understand going 12 hours from UTC in each direction, one hour per timezone. I think I understand 13 hours in each direction, for daylight savings time. I just dont get 14 hours? ...

How can I configure ASP.NET web service to only send LocalDateTime property of DateTimeOffset object as JSON?

I have a bunch of entity class (generated by Linq to SQL) with a few DateTimeOffset properties in it. When I send that over the wire as JSON from a .asmx web service, the JSON serializer generates the following JSON: {"DateTime":"\/Date(1252142834307)\/", "UtcDateTime":"\/Date(1252142834307)\/", "LocalDateTime":"\/Date(1252142834307...

Parse string as DateTimeOffset in Expression<Func<T, bool>>

Hey, I am trying to create an Expression<Func<T, bool>> in which a string property is converted/cast to a DateTimeOffset so that DateTimeOffset operations can be performed on it. We are using Linq2SQL as our data provider, which does support converting strings to the SQL equivalent of DateTimeOffset. Ideally I want the expression to be...

Sql Server DateTime to DateTimeOffset

I have an old table with a few rows that has a datetime column. I want to switch this to datetimeoffset but i want to be able to transfer the data that already exists. So i'm doing something like [1]. This works but the offset set is 0 when i do the dattime to datetimeoffset assignment. Fortunately the offset that i want to set it to i...

DateTimeOffset adding TimeSpan returns invalid UTC offset for its TimeZoneInfo

I am in the process of building a temporal expression library that must be properly globalized and therefore work in all available Time Zones. Now I seem to be stuck as I'm not sure how to retrieve adjusted dates from DateTimeOffset objects in the correct Daylight Savings Time (DST) when the transition boundary is crossed using any vari...

Unit testing NHibernate w/ SQLite and DateTimeOffset mappings

Porting over an application to use NHibernate from a different ORM. I've started to put in place the ability to run our unit tests against an in memory SQLite database. This works on the first few batches of tests, but I just hit a snag. Our app would in the real world be talking to a SQL 2008 server, and as such, several models cur...

Losing DateTimeOffset precision when using C#

I have a SQL Server table with a CreatedDate field of type DateTimeOffset(2). A sample value which is in the table is 2010-03-01 15:18:58.57 -05:00 As an example, from within C# I retrieve this value like so: var cmd = new SqlCommand("SELECT CreatedDate FROM Entities WHERE EntityID = 2", cn); var da = new SqlDataAdapter(cmd); D...

Daylight saving time and Timezone best practices

I am hoping to make this question and the answers to it the definitive guide to dealing with daylight saving time, in particular for dealing with the actual change overs. If you have anything to add, please do Many systems are dependent on keeping accurate time, the problem is with changes to time due to daylight savings - moving the c...

Entity Framework 4 maps DateTimeOffset to SQL datetime in Visual Studio 2010

I'm using Visual Studio 2010 RTM with .NET/Entity Framework 4 RTM with a model driven design approach. When I create an entity with a DateTimeOffset field the EF modeler tries to map the DateTimeOffset to a SQL datetime instead of a SQL datetimeoffset. I'm using SQL Server 2008 Express so the datetimeoffset is supported in the database. ...

Safely convert UTC datetimes to local time (based on TZ) for calculations?

Following from my last question which @Jon Skeet gave me a lot of help with (thanks again!) I am now wondering how I can safely work with date/times, stored as UTC, when they are converted back to Local Date/Time. As Jon indicated in my last question using DateTimeOffset represents an instant in time and there is no way to predict wha...

Getting DateTimeOffset value form SQL 2008 to C#

I have a SQL 2008 table with a field called RecDate of type DateTimeOffset. For a given record the value is '2010-04-01 17:19:23.62 -05:00' In C# I create a DataTable and fill it with the results of "SELECT RecDate FROM MyTable". I need to get the milliseconds, but if I do the following the milliseconds are always 0: DateTime...

Migrate SQLExpress to MySQL datetimeoffset issue

Hi, i'm trying to migrate from sqlexpress to mysql, and am having an issue with the DateTimeOFfset(7) field in one of my tables. MySQL is refusing to handle it.. Is there a way to get around this? ...

How can I convert my DateTimeOffset to a Twitter Date/Time ?

Hi folks, How can I convert a DateTimeOffset.Now into a twitter-compatible date/time? Twitter example: <created_at>Tue Apr 07 22:52:51 +0000 2009</created_at> cheers :) ...