473,378 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Convert Character Type Date to use DateDiff function

Hello,

I have gone through some of the other solutions to similar problems posted here, but none seemed to work for me. So, as a last ditch effort I posting this in hopes someone can help. This is what I have.

SQL table
column terminateddate - varchar type with date stored as mm/dd/yyyy

On an ASP page I'm trying to put together a SELECT statement that compares two dates, the one in the table and a requested variable. Here is what I have so far...

SQL = "SELECT * FROM table where datediff(d,Convert(varchar(20),Convert(datetime,te rminateddate), 101),""&requestedvariable&"") < 30 ORDER by lastname"

However, no matter how I change it all I get is the same error (below).

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Am I doing something wrong, any help would be great. I have several other projects to get down and this is holding me up.

Thanks
Aug 14 '07 #1
2 9993
ck9663
2,878 Expert 2GB
Hello,

I have gone through some of the other solutions to similar problems posted here, but none seemed to work for me. So, as a last ditch effort I posting this in hopes someone can help. This is what I have.

SQL table
column terminateddate - varchar type with date stored as mm/dd/yyyy

On an ASP page I'm trying to put together a SELECT statement that compares two dates, the one in the table and a requested variable. Here is what I have so far...

SQL = "SELECT * FROM table where datediff(d,Convert(varchar(20),Convert(datetime,te rminateddate), 101),""&requestedvariable&"") < 30 ORDER by lastname"

However, no matter how I change it all I get is the same error (below).

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Am I doing something wrong, any help would be great. I have several other projects to get down and this is holding me up.

Thanks
either (or both) of your variable have an invalid date and take note of this from online help:

"DATEDIFF produces an error if the result is out of range for integer values. For milliseconds, the maximum number is 24 days, 20 hours, 31 minutes and 23.647 seconds. For seconds, the maximum number is 68 years."
Aug 14 '07 #2
fplesco
82
Hello,

I have gone through some of the other solutions to similar problems posted here, but none seemed to work for me. So, as a last ditch effort I posting this in hopes someone can help. This is what I have.

SQL table
column terminateddate - varchar type with date stored as mm/dd/yyyy

On an ASP page I'm trying to put together a SELECT statement that compares two dates, the one in the table and a requested variable. Here is what I have so far...

SQL = "SELECT * FROM table where datediff(d,Convert(varchar(20),Convert(datetime,te rminateddate), 101),""&requestedvariable&"") < 30 ORDER by lastname"

However, no matter how I change it all I get is the same error (below).

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Am I doing something wrong, any help would be great. I have several other projects to get down and this is holding me up.

Thanks

Hey -

You may try this one
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM table 
  2. where datediff(d, Convert(char(10),terminateddate, 121),CONVERT(char(10), " & requestedvariable &",121)) < 30 ORDER by lastname
  3.  
Aug 15 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Lynn | last post by:
On a form I have Date_Start Date_End I have a new Date_Start1 Date_End1 which the use inputs. I need to validate that Date_Start1 and...
19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
0
by: UBI | last post by:
Vorrei suggerire una funzione completa per la differenza fra due date. (questo è codice freeware, niente di illegale) La funzione seguente permette il calcolo di una differenza precisa tra due...
5
by: jnikle | last post by:
I have two completely unrelated tables, one for reviews and another for pay periods. The reviews table has a review date in it, and the pay periods table is just a list of the beginnings of pay...
1
by: Wes Peters | last post by:
I have a situation where I want to filter records for a given day. The field that stores the date/time uses the date() function as a default value, kind of a date/time stamp for the record. The...
19
by: Lysander | last post by:
I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the...
1
by: Coll | last post by:
I have a function that calculates a period of time e.g. 2.3 years, .5 years etc. I was using the function in a query, but since I had not declared a data type for the function, it wasn't sorting...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time 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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.