Solved

LINQ DateTime Format

Posted on 2008-11-03
8
1,405 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
ID: 22865747
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
ID: 22865796
It is in a DateTime Data Type & not in a string format
0
 
LVL 7

Accepted Solution

by:
moseack earned 250 total points
ID: 22865855
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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 49

Assisted Solution

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

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

/gustav
0
 

Author Comment

by:u2envy1
ID: 22874140
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
ID: 22874709
No problem.

/gustav
0
 

Author Closing Comment

by:u2envy1
ID: 31512623
Thx guys......
0
 
LVL 7

Expert Comment

by:moseack
ID: 22876977
Always happy to help
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

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