Solved

LINQ DateTime Format

Posted on 2008-11-03
8
1,393 Views
Last Modified: 2010-05-18
Im converting all code from ADO.net to LINQ. In ADO i could add a DateTime field into SQL when adding a record. Im doing the same with LINQ & im getting an error. SqlDateTime Overflow. Must be between 1/1/1753 12:00:00 AM  AND 12/31/9999 11:59:59 PM. My format is 2008/11/03 11:00:00 AM. How can I make it take this format & store it in sql server as the required format & not throw this error ?
0
Comment
Question by:u2envy1
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:moseack
Comment Utility
Sinse LINQ2SQL is based on native CLR types, you should convert your DateTime string to a Sytem.DateTime object. You can use DateTime.Parse.
0
 

Author Comment

by:u2envy1
Comment Utility
It is in a DateTime Data Type & not in a string format
0
 
LVL 7

Accepted Solution

by:
moseack earned 250 total points
Comment Utility
Not just in the DB, but also in the code?

var q = from o in DB.MockTableWithDate

        where o.Date == DateTime.Parse("2008/11/03 11:00:00 AM")

        select o;

Open in new window

0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 250 total points
Comment Utility
> My format is 2008/11/03 11:00:00 AM ..

Yep, Mose is close. A DateTime variable does not carry a format.

/gustav
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:u2envy1
Comment Utility
Sorry guys. I was passing a dateTime value & a null for a EditDate field. I had to add DBNull.Value for the DateTime field.
All Help much appreciated thou
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
No problem.

/gustav
0
 

Author Closing Comment

by:u2envy1
Comment Utility
Thx guys......
0
 
LVL 7

Expert Comment

by:moseack
Comment Utility
Always happy to help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now