473,406 Members | 2,713 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,406 software developers and data experts.

Date Format - best way of converting a string into a date format

I am guessing that this must be a common question, but I just can't
find a simple solution for it by searching the newsgroups. I have a
Text Box with a date in a UK format. The format has been verified and
is legal. Now all I want to do is pop it into an SQL field. Debugging
on my local machine everything works with the following:

dDOB = CDate(txtDOB)
Row.Item("DOB") = dDOB

But when deployed this would fail because CDate requires MM/DD/YYYY
rather than DD/MM/YYYY.

In short I want to display and collect dates from users with the date
format DD/MM/YYYY which is fine on my local machine, but not on my
server farm. If I use string manipulation to solve this, it works on
my server farm but not on my local machine. I could write some
un-elegant code to solve this, but I am convinced there must be a
simple way of overcoming this problem.

Thanks in advance for any help.

Brian Candy

Nov 18 '05 #1
2 2719
Hi, Brian Candy,

You can try the static method ParseExact on the System.DateTime structure:

http://msdn.microsoft.com/library/en...ExactTopic.asp

And then pass the DateTime value as a parameter to insert it into the DB.

Greetings
Martin
"Brian Candy" <br***@01792.com> wrote in message
news:ja********************************@4ax.com...
I am guessing that this must be a common question, but I just can't
find a simple solution for it by searching the newsgroups. I have a
Text Box with a date in a UK format. The format has been verified and
is legal. Now all I want to do is pop it into an SQL field. Debugging
on my local machine everything works with the following:

dDOB = CDate(txtDOB)
Row.Item("DOB") = dDOB

But when deployed this would fail because CDate requires MM/DD/YYYY
rather than DD/MM/YYYY.

In short I want to display and collect dates from users with the date
format DD/MM/YYYY which is fine on my local machine, but not on my
server farm. If I use string manipulation to solve this, it works on
my server farm but not on my local machine. I could write some
un-elegant code to solve this, but I am convinced there must be a
simple way of overcoming this problem.

Thanks in advance for any help.

Brian Candy

Nov 18 '05 #2
Hey Brian,

Sounds like your web server farm is set up using US settings. You can set
the localisation to uk formatting by doing one of two things:

1) Setting the locale identifier in the page directive: <%@ Page
LCID="2057" Language="VB" %>
2057 is the locale for UK. This will work on the page in question.

2) Setting the culture for the entire site. This has to be done in
web.config by applying the following tag within <system.web>
<globalization culture="en-GB" uiCulture="en" ></globalization>

Hope that helps.

Janaka

"Brian Candy" <br***@01792.com> wrote in message
news:ja********************************@4ax.com...
I am guessing that this must be a common question, but I just can't
find a simple solution for it by searching the newsgroups. I have a
Text Box with a date in a UK format. The format has been verified and
is legal. Now all I want to do is pop it into an SQL field. Debugging
on my local machine everything works with the following:

dDOB = CDate(txtDOB)
Row.Item("DOB") = dDOB

But when deployed this would fail because CDate requires MM/DD/YYYY
rather than DD/MM/YYYY.

In short I want to display and collect dates from users with the date
format DD/MM/YYYY which is fine on my local machine, but not on my
server farm. If I use string manipulation to solve this, it works on
my server farm but not on my local machine. I could write some
un-elegant code to solve this, but I am convinced there must be a
simple way of overcoming this problem.

Thanks in advance for any help.

Brian Candy

Nov 18 '05 #3

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

Similar topics

3
by: J. Muenchbourg | last post by:
while inserting new records into SQL, i'm using the folloinwg sqlstatement> Dim MySQL as string = "Insert into roster (pname, pnotes, thedate) values (@pname, @pnotes, @thedate)" the sql...
4
by: Tony | last post by:
Hey guys, I use Google Groups quite a bit as it is an enormous wealth of information, and now I need some help. I have created a query using parameters to capture a range of date, the date is...
1
by: Amal Ismail | last post by:
hello i'm inquiring about something .. hope to find help here i'm using ASP.NET Mobile web application using c# And i'm facing a problem , i use SQL server Database I've table inside it a...
8
by: John Wildes | last post by:
Hello all I'm going to try and be brief with my question, please tell me if I have the wrong group. We are querying transaction data from a DB3 database application. The dates are stored as...
3
by: seegoon | last post by:
Hi to all. I have a small problem I hope someone can help me with. I am running a sql query to a csv file. The query searches for the total of a column between 2 dates. This is a copy of one of...
6
by: marc | last post by:
hi im trying to convert Date() into a unix timestamp so i can stick the result into a mysql db, please help!
2
by: Brian Parker | last post by:
I am beginning to work with VB2005.NET and I'm getting some problems with string formatting converting an application from VB6. VB6 code:- sTradeDate = Format(pArray(4,i Record), "mmddyy") ...
3
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying...
30
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.