.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Why is DateTime not blittable?

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :WPF

I'm a little unclear on something.

Decimal and DateTime are just structs, the Decimal type contains four Int32 fields, and because these are blittable a Decimal is indeed blittable.

DateTime is a struct too, it contains a single UInt64 field, because this is blittable I'd expect DateTime to be blittable but it isn't.

My understanding is that any struct or class that has LayoutKind.Sequential AND contains ONLY blittable fields, is itself blittable.

My research into this suggests that DateTime, although it is a struct, is not formatted with LayoutKind.Sequential and this is why it isn't blittable. It seems to have been defined with Auto layout and this is the reason it isn't blittable.

However, I don't know how or why this was done by MS, the C# language rules say that ALL structs have LayoutKind.Sequential applied BY DEFAULT.

Does anyone know more about this odd behaviour from DateTime?

Incidentally, you can test for blittable easily by just calling:

GCHandle pinStructure = GCHandle.Alloc(item, GCHandleType.Pinned);

If no exception is thrown, then the type of 'item' is a blittable type.

I suspect that they deliberately made DateTime non-blittable to avoid confusion with existing Win32 date time structs, making DateTime blittable migh lead people to believe they can marshal it to one

View Complete Post

More Related Resource Links

How to format datetime & date with century?

Execute the following Microsoft SQL Server T-SQL datetime, date and time formatting scripts in Management Studio Query Editor to demonstrate the usage of the multitude of temporal data formats available and the application of date / datetime functions.


Essential SQL Server Date, Time and DateTime Functions

The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any formatting considerations at all.

datetime server



I'd like to have the date and time from server.

DateTime.Now Is ok?

Must be something else?


System.DateTime.AddDays: Value to add was out of range.


I'm getting the following error:

[ArgumentOutOfRangeException: Value to add was out of range.
Parameter name: value]
   System.DateTime.Add(Double value, Int32 scale) +7657639
   System.DateTime.AddDays(Double value) +19

The line from which this error originates has the following code:

expires = Now.AddDays(30)

It occurs irregularly and irreproducably. The server date/time is correct and set to GMT. I've heard that it could be some curiosity to do with timezones, but that is speculative.

It seems that we're some time from the year 10,000 yet, so I can't understand why adding thirty days to the current time could cause this! Any ideas? Culture settings perhaps?

Linq to SQL returns null for DateTime fields.


I have a linq to sql entity class in which I declared some DateTime fileds like this:

[Column(DbType = "smalldatetime")]
public DateTime? StartDate { get; set; }

And this is how I fetch data form repository:

return repository.Logs.OrderByDescending(l => l.LogID).FirstOrDefault();

All non DateTime fields are filled properly but all datetimes are null.

[Column(DbType = "smalldatetime")]

        public DateTime? StartDate { get; set; }

How Convert Datetime (YYYY/MM/dd HH:mm:ss) To yyyy-MM-dd



How do you write a date value to an XMLElement in .NET 3.5 XMLDocument object. 


 I am using the following:


DateTime orderDate = new DateTime();
orderDate = DateTime.Now; // 2010-08-24 16:45:46

string st = XmlConvert.ToString(orderDate, "yyyy-MM-dd");     // st="2010-08-24"
DateTime dt2 = XmlConvert.ToDateTime (st, "yyyy-MM-dd");   // dt2 = "2010-08-24 00:00:00"

I would like to remove the time section "00:00:00". I only need to write a date in the XML file with the following format :


Order date is defined like this in the xsd file : <xs:element name="OrderDate" type="xs:date"/>


Thanks for your support.




when i do something like this:

var time = DateTime.Parse("2010-01-03T17:08:33+01:00");

i get an object  of kind 'local' with the time set to 17:08:33, the extra hour is lost. Why does this happen and how can i fix it?

Actually the string representation of the time is received from a java web service and there is no way of changing the implementation of the service.



ReadOnly DateTime attribute stores correct date but only retrieves DateTime.MinValue on Delete


Hey everyone,

I have a dynamic data site that stores Event data using LINQ-to-SQL. When someone requests an event, it is first stored as a PendingEvent (which is a child of Event) with a column/attribute called receivedAt, which is [ReadOnly(true)] and which is assigned in InsertEvent as shown.

        partial void InsertEvent(Event instance)
            instance.requestedAt = DateTime.Now;




This works fine. The event displays with the correct receivedAt date, and it's correct in my database. It shows up just fine on my Display, Edit, and List pages. However, if I try to delete, the receivedAt in the instance (retrieved with my debugger) in my delete function is 01/01/0001 12:00am, also known as DateTime.MinValue. My other dates appear correct.

If I remove "ReadOnly(true)" from the received at, everything works fine. Why won't "ReadOnly" allow me to have a time?
Thanks in advance,



I forgot to mention why I care. I can't submit the instance to be deleted because DateTime.MinValue is outside SQL's available datetime, so I get a SQL error. The delete also takes place in a custom dele

ASP.NET DateTime Conversion strange behaviour



I am working on ASP.NET web application where we are using javascript calendar to accept the date in textboxes. The date format is dd/mm/yyyy. The application is running in US and UK environments.

I am facing issues in US environment while storing the dates so I have added 2 keys in config file viz culture which will be either en-US or en-GB depending on the deployment location and baseCulture which will always be en-GB.

In the code, I have added a condition which checks if culture and baseCulture values are not matching then do the conversion of date in US format.

But I have found that the code converts the date from dd/mm/yyyy to mm/dd/yyyy when the key is baseCulture (en-GB) and it throws FormatException when key is culture (en-US).

I am bit confused by this behaviour. Is this normal? Can any one please explain more about this? Note: I am working on a machine which has en-US as language and culture

<add key="culture" value="en-US" />
<add key="baseCulture" value="en-GB" />
// This line works and converts the date from 26/08/2010 to 08/26/2010
// Here the baseCulture is en-GB.
DateTime dt = DateTime.Parse(txtCurrentDate,baseCulture)

// This line throws FormatException. culture 

DateTime custom managed property search fails with " Your query is malformed. Please rephrase your q

I've created a front end search page in Silverlight 4 for SharePoint Search.  Currently we are using WSS 3.0 + Search Server Express 2008 (v  The page interacts with the MOSS version of the search web service at:   <site collection>/_vti_bin/search.asmx The reason for this approach is the unique way the requirements specify the look and behavior of the results.  The built-in Search Center page or web parts will not satisfy these requirements. We are going into production but I still cannot figure out how to search against my custom managed properties that are of Type DateTime.  If I cannot get this to work, it is a showstopper. I've tried numerous variations on the SQL Syntax and cannot get it to work.  I know the error is in the date portion of the WHERE clause since I can remove it and searches work fine. Here is a working query: SELECT Size, Rank, Path, Title, Description, Write, RequestSubmittedDate, DocumentType, RequestPromisedDate, ProblemDescription, DatePublished, RequestOwner, RequestingDepartment, DocumentAuthor, ProjectNumber, ProjectDescription, RequestStatus FROM scope() WHERE CONTAINS ('"nmr"') ORDER BY "Rank" DESC yet if I try to use a date literal in the WHERE clause as in the following query modification, I get the "malformed"

How to change The DateTime Automatically according to User TimeZone Offset?

I have an application in which we are displaying DateTime in many pages. we want to display these DateTime's according to UserTime zone. UserTimeZone will be in database. All DateTime values will be saved int UTC format. My Requirement is I want set the TimeZoneOffset of user in ServerSide based on the User TimeZoneOffset All the DateTime values needs to be Added/Substracted while showing the DateTime values to user. I dont want to manully add/substract TimeZoneOffset value in all pages. Is there any way the DateTime  automatically change to the User Timezone.  How can I do this? Thanks in Advance ChellamNaidu

Data validation for datetime parameter in SSRS

Hi,   I wanted to know more about validation of SSRS parameters. I have a simple report which has a parameter called startdate of DateTime datatype. The datetime parameter in SSRS takes manual input as well. So, the user can enter any junk value. I want to ensure that the input parameter is in correct format and I want to display an error msg when the format is incorrect. My report has the following VB code for validation:   Public Function Validate( ByVal startdate As String) As BooleanIf IsDate(startdate) = True Then Return TrueElse Return FalseEnd IfEnd Function   And my report has a textbox which has the expression property set to; =Code.Validate(Parameters!startdate.Value) the textbox on the report has to display if the entered date is valid or not.   But, when i enter an erroneous date, SSRS doesn't render the report and throws a generic error. This happens even before the code written for validating the parameter executes.   Also couldn't find a way to disable the manual input for the datetime parameter. Even that would solve the problem.   Another alternative was to make the startdate parameter as string, but i want the calendar control button to be provided for the user.

Data Conversion - string to datetime help!!!

Hi all, I need help on concatenate two fields into one then display it as datetime format as such yyyy-mm-dd hh:mm:ss AM/PM. The db is on SQL 2008 SP1. The date and time columns are on the same table and store as varchar. Date has varchar(10) and time has varchar(16). Date column shows result from query is 20100827 while the time column is either 070101.000000 or 070101. The question is how go about concatenate the two together and display in the format above in a report? How should I write my select query for this report? I am using SQL 2008 R2 BI Development Studio to design my report. Thank you. VCHS

Need help in datetime conversion excluding invalid records

I have varachar(50) field which have date in yyyymmdd format Now i have to filter the data which are greater then server date I have following query Select * from MDB_CONTENT_INFO Where convert(datetime, CON_SCHEDULED_INDUCTION_DATE,112) >= GetDate() Problem ist aht i may have some invalid data other then valid one. I am getting error The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. or Conversion failed when converting date and/or time from character string. I wanted to exclude those records but currently getting error for the query asKamran Shahid Senior Software Engineer/Analyst (MCP,MCAD,MCSD.NET,MCTS,MCPD.net[web])

SP Datetime parameter requires time input

I'm working on a Crystal report that contains 4 subreports.  Each subreport passes 2 date parameters to a stored procedure.  This works, but only if a value for time is also entered in the Crystal parameter prompt. How can I fix the stored procedure so these parameters will accept only a date as input?

Sql DateTime2 to .NET DateTime conversion results in out-of-range exception

I posted it in C# General because I thought that the subject was not Sql Smo related, although I use Smo extensively even in this routine for connection. Unfortunately after a few days no constructive suggestion has been advanced. Two posts the thread collected are not helpful. I am wondering if Alok or someone else with the status of MSFT Sql Server developers take a look at this very importan problem for me which became a stumbling block.Thanks. AlexB - Win_7 Pro64, SqlSer64 WinSer64

How to set the default value for a datetime culomn?

I try to set a default value  (getdate())  for a datetime culomn in sql mobile,  but got error when i insert record: there was a syntax error in the date format. [expression = getdate()] may be I can only set a exict date ?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend