472,985 Members | 2,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Writing value to datetime field in SQL database in dd/mm/yyyy format

Hello,

I'm hoping i'm posting to the correct newsgroup - this question involves
both a SQL database and VB. I am a newbie and i'm writing a program in
which one of a handful of fields will have a date entered. The contents of
this field (and others) need to be written back to a SQL database.

The 'date' field will be input in the format of the Regional settings
(mainly dd/mm/yyy for the UK). When it comes to the point where it is
written to the SQL database, VB changes the date to mm/dd/yyyy format. The
SQL server is expecting the date in the format dd/mm/yyyy so returns an
error saying the date is out of range.

Is there a simple way around this problem that I have missed as I am sure
other people must have stumbled upon this before?

If I could work through this problem I could get into some proper
development!

Any thoughts would be really appreciated...

Thanks!

Ben
Nov 20 '05 #1
5 8356
Hi Ben,

You should be able to do something like this:
mdatestring = mdate.ToString("ddmmyyyy")

HTH,

Bernie Yaeger

"Ben Williams" <be**********@uk.fujiseal.com> wrote in message
news:40***********************@newscene.com...
Hello,

I'm hoping i'm posting to the correct newsgroup - this question involves
both a SQL database and VB. I am a newbie and i'm writing a program in
which one of a handful of fields will have a date entered. The contents of this field (and others) need to be written back to a SQL database.

The 'date' field will be input in the format of the Regional settings
(mainly dd/mm/yyy for the UK). When it comes to the point where it is
written to the SQL database, VB changes the date to mm/dd/yyyy format. The SQL server is expecting the date in the format dd/mm/yyyy so returns an
error saying the date is out of range.

Is there a simple way around this problem that I have missed as I am sure
other people must have stumbled upon this before?

If I could work through this problem I could get into some proper
development!

Any thoughts would be really appreciated...

Thanks!

Ben

Nov 20 '05 #2
Cor
Hi Bernie,

This is typical a problem for OHM

:-)

Cor
Nov 20 '05 #3


Thanks for your reply. That works....almost!

It converts the date but it seems to miss out the month

i.e. "16002004"

This is the code snippet:

Dim dteDueDate As DateTime
Dim strDueDate As String

'Convert dteDueDateA.Text to ddmmyyyy
dteDueDate = dteInputDate.Text
strDueDate = dteDueDate.ToString("ddmmyyyy")

If I step through the code now and replace the 00 with 02 it will write
it to the database which is a major step forward!

I'm so close now - any thoughts would again be appreciated!

Ben

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4
* "Ben Williams" <be**********@uk.fujiseal.com> scripsit:
I'm hoping i'm posting to the correct newsgroup - this question involves
both a SQL database and VB. I am a newbie and i'm writing a program in
which one of a handful of fields will have a date entered. The contents of
this field (and others) need to be written back to a SQL database.

The 'date' field will be input in the format of the Regional settings
(mainly dd/mm/yyy for the UK). When it comes to the point where it is
written to the SQL database, VB changes the date to mm/dd/yyyy format. The
SQL server is expecting the date in the format dd/mm/yyyy so returns an
error saying the date is out of range.


Why not use a parameter with the insert command?

More info:

<news:microsoft.public.dotnet.framework.adonet>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
Hi Ben,

A very simple change will solve the problem:

strDueDate = dteDueDate.ToString("ddMMyyyy") ' use caps for month

HTH,

Bernie

"Ben Williams" <be**********@uk.fujiseal.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...


Thanks for your reply. That works....almost!

It converts the date but it seems to miss out the month

i.e. "16002004"

This is the code snippet:

Dim dteDueDate As DateTime
Dim strDueDate As String

'Convert dteDueDateA.Text to ddmmyyyy
dteDueDate = dteInputDate.Text
strDueDate = dteDueDate.ToString("ddmmyyyy")

If I step through the code now and replace the 00 with 02 it will write
it to the database which is a major step forward!

I'm so close now - any thoughts would again be appreciated!

Ben

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marcos Rodríguez | last post by:
Hi all I have an Access Data Base containing a table which have a DateTime Field. I am creating a Windows App and I am using a DataGrid object to show data from the table using a DataSet object. My...
1
by: faktujaa | last post by:
Hi, I have date in a string format like string strDate = "110204". Now i want to convert this string to MM/dd/yyyy format. How do i do this???? I used string.Format(strDate, "MM/dd/yyyy") but no...
3
by: Iwan Petrow | last post by:
Hi, I have a column of type datetime in a SQL Server database. I set and get this column with Web Services using dataset and send them to a Web App TextBox control. The collation of the database...
2
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
4
by: javatopia | last post by:
Hello, I am trying to show a Crystal Reports 10 Enterprise report in an ASP.NET page (C#). I can run the report via the admin console just fine. When I try to show the report, after setting up...
8
by: Dominique Vandensteen | last post by:
I have a datetime and want to format it to "quarter year" so 20 december 2003 should give: "4-2003" is this possible? I don't find a format character for quarter :-( Dominique
1
by: Esref Durna | last post by:
my sql server have this datetime format ( yyyy-mm-dd ) how could i change it to dd.mm.yyyy format or what should i do? thanks
15
by: JenHu | last post by:
Hi expert, I have a data field (birthdate) contains a datetime datatype (mm/dd/yyyy), how can I convert to mmdd?? say, the birthday is 8/1/1979 and convert to mmdd DOB =...
0
by: georges the man | last post by:
The purpose: • Sorting and Searching • Numerical Analysis Design Specification You are to write a program called “StockAnalyser”. Your program will read a text file that contains historical...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.