468,512 Members | 1,448 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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 8234
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Marcos Rodríguez | last post: by
3 posts views Thread by Iwan Petrow | last post: by
2 posts views Thread by Benedict Teoh | last post: by
8 posts views Thread by Dominique Vandensteen | last post: by
1 post views Thread by Esref Durna | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.