473,396 Members | 1,997 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,396 software developers and data experts.

A problem with dates.

6
Hi,
I keep getting an error when I run my code. Here’s the error “The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated”. It points to this part of my code…
Expand|Select|Wrap|Line Numbers
  1.  cmd.ExecuteNonQuery() 
Here’s my code…
Expand|Select|Wrap|Line Numbers
  1.     Private Sub TestDate()
  2.         Dim DateClosedString As String = "Closed"
  3.         Dim cnn As Data.SqlClient.SqlConnection
  4.         Dim cmd As Data.SqlClient.SqlCommand
  5.         Dim TodayTest As Date = Today
  6.         Dim strSQL2 As String
  7.  
  8.         strSQL2 = "Update TestTBL SET DateStatus = '" & DateClosedString & "' WHERE EndDate >= '" & Today & "'"
  9.         Dim conn As String
  10.         conn = "Data Source=.\SQLEXPRESS;AttachDbFilename=""|DataDirectory|\aspnetdb.mdf"";Integrated Security=True;User Instance=True"
  11.         cnn = New Data.SqlClient.SqlConnection(conn)
  12.         cmd = New Data.SqlClient.SqlCommand(strSQL2, cnn)
  13.         cnn.Open()
  14.         cmd.ExecuteNonQuery()
  15.         cnn.Close()
  16. End Sub 
What I want it to do is check my TestTBL and if any EndDates are greater or equal to todays date, write closed to the DateStatus field.
The dates are saved to the database as DateTime. This is copy and passed from an enddate field in my database “22/05/2007 00:00:00”. I’m not really need the time part but I cant find any other way.
Can anyone help? I’ve been pulling my hair out over this one for days.
May 13 '07 #1
3 994
vanc
211 Expert 100+
I think your sql needs some characters like "# date #" in access database.

hope this help.
May 14 '07 #2
Hi! try inserting a string with the next format:

year/month/day hh:mm:ss

something like String.Format("{0}/{1}/{2} {3}:{4}", date.Year,date.Month,date.Day,date.Hour,date.Minut e)

to give to the DB engine a common string wich is accepted at least in SQLServe, Postgres and Oracle

I hope it helps :D
May 14 '07 #3
CaJack
6
Hi! try inserting a string with the next format:

year/month/day hh:mm:ss

something like String.Format("{0}/{1}/{2} {3}:{4}", date.Year,date.Month,date.Day,date.Hour,date.Minut e)

to give to the DB engine a common string wich is accepted at least in SQLServe, Postgres and Oracle

I hope it helps :D
Yep sorted it, thank you.
May 15 '07 #4

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

Similar topics

7
by: Alistair | last post by:
diary_date = request.form("diary_date") - (from a populated drop down list) strSQL = "SELECT saz_title, saz_text from saz_details where saz_date =#" & diary_date & "#" a response.write...
10
by: Colin Steadman | last post by:
I'm a stupid ASP programmer and I dont do Javascript (except for very simple tasks anyway), and I'm in a bit of a predicament. I've used a javascript table sorting script from here: ...
2
by: Douglas | last post by:
I have a Vehicle MOT field in my table which i have as a Date field I dont really want to hold the year, just 'dd mmm' as MOTs are the same date every year. I have the field on my form as a...
1
by: Don Sealer | last post by:
I have a report that includes 5 different subreports. I'd like to be able to open this report using a date function (Start Date and End Date). I'd like all five subreports to show the data from...
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
3
by: StBond | last post by:
Hi everyone, I am new to Access and Visual Basic so things my be getting across a bit cloudy. I only started using VB for one week. I am having a little problem with the database that I am...
12
by: Dixie | last post by:
I am trying to calculate the number of workdays between two dates with regards to holidays as well. I have used Arvin Meyer's code on the Access Web, but as I am in Australia and my date format is...
13
numberwhun
by: numberwhun | last post by:
Hello everyone! I have a data file that contains miscellaneous information on each line. (Unfortunately, I cannot go into detail of the file layout as it is sensitive information), but I can say...
12
by: jonathan184 | last post by:
Hi the purpose of the script I am trying to do is to access a dir and run the ls -l command which will show the files and the modified date, no w the script is to check two files in that dir , if the...
2
by: angi35 | last post by:
Hi, I'm working in Access 2000. I have a form with a series of date fields, showing the progress of a project from start to completion. There's a set of fields/controls for projected dates (when...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.