PC Review


Reply
Thread Tools Rate Thread

Date Difference

 
 
td
Guest
Posts: n/a
 
      5th Oct 2008
The query
SELECT DATEDIFF(Day, [DateOut], [DateIn]) AS Days FROM Calibrations;
gives error "Overflow"

All dates entered are entered in dd/mm/yyyy format. The error can be fixed
by setting the default Logon locale to British English. I have tried the
CONVERT function as follows

SELECT DATEDIFF(Day, CONVERT(varchar(10), [DateOut], 120),
CONVERT(varchar(10), DateIn, 120)) AS Days FROM Calibrations;
gives error: "Conversion of char datatype to DateTime results in Out-Of-Range"
 
Reply With Quote
 
 
 
 
Sylvain Lafontaine
Guest
Posts: n/a
 
      5th Oct 2008
Probably because DateIn and DateOut are stored as a type string, not as
DateTime or ShortDateTime. If these fields are of type characters, setting
a format such as 120 will change absolutely nothing because you are
converting from a type string to another type string; ie., doing nothing
excerpt maybe truncating after 10 characters.

Use the command « set dateformat dmy » before computing your DateDiff or
change your convert function to convert toward a DateTime format instead of
converting toward the varchar(10) format.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


"td" <(E-Mail Removed)> wrote in message
news:0C36D6A4-83BA-42FB-824B-(E-Mail Removed)...
> The query
> SELECT DATEDIFF(Day, [DateOut], [DateIn]) AS Days FROM Calibrations;
> gives error "Overflow"
>
> All dates entered are entered in dd/mm/yyyy format. The error can be fixed
> by setting the default Logon locale to British English. I have tried the
> CONVERT function as follows
>
> SELECT DATEDIFF(Day, CONVERT(varchar(10), [DateOut], 120),
> CONVERT(varchar(10), DateIn, 120)) AS Days FROM Calibrations;
> gives error: "Conversion of char datatype to DateTime results in
> Out-Of-Range"



 
Reply With Quote
 
td
Guest
Posts: n/a
 
      5th Oct 2008
Sometimes you miss the obvious. I have looked for this error for days but did
not check as I KNEW they were DateTime. But before replying to you that they
were I did a double check. Ooops!!!
Thanks

"Sylvain Lafontaine" wrote:

> Probably because DateIn and DateOut are stored as a type string, not as
> DateTime or ShortDateTime. If these fields are of type characters, setting
> a format such as 120 will change absolutely nothing because you are
> converting from a type string to another type string; ie., doing nothing
> excerpt maybe truncating after 10 characters.
>
> Use the command « set dateformat dmy » before computing your DateDiff or
> change your convert function to convert toward a DateTime format instead of
> converting toward the varchar(10) format.
>
> --
> Sylvain Lafontaine, ing.
> MVP - Technologies Virtual-PC
> E-mail: sylvain aei ca (fill the blanks, no spam please)
>
>
> "td" <(E-Mail Removed)> wrote in message
> news:0C36D6A4-83BA-42FB-824B-(E-Mail Removed)...
> > The query
> > SELECT DATEDIFF(Day, [DateOut], [DateIn]) AS Days FROM Calibrations;
> > gives error "Overflow"
> >
> > All dates entered are entered in dd/mm/yyyy format. The error can be fixed
> > by setting the default Logon locale to British English. I have tried the
> > CONVERT function as follows
> >
> > SELECT DATEDIFF(Day, CONVERT(varchar(10), [DateOut], 120),
> > CONVERT(varchar(10), DateIn, 120)) AS Days FROM Calibrations;
> > gives error: "Conversion of char datatype to DateTime results in
> > Out-Of-Range"

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference betwen Excel Date () Function and System Date Khalil Microsoft Excel Worksheet Functions 2 16th Jun 2009 01:10 PM
Difference System date and Excel Date function Khalil Microsoft Excel Worksheet Functions 2 16th Jun 2009 11:23 AM
Calculate date difference between fixed date and current date Dave Elliott Microsoft Access Forms 3 23rd May 2005 03:54 AM
date difference using current date is no date is entered =?Utf-8?B?QmV0c3lL?= Microsoft Access Queries 5 7th Apr 2005 04:53 PM
Message box prompts for a date and the calculates difference in todays date robertguy Microsoft Excel Misc 7 13th Mar 2004 08:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:16 AM.