473,394 Members | 1,706 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,394 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 8376
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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:
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.