Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Date Format - best way of converting a string into a date format

Reply
Thread Tools

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

 
 
Brian Candy
Guest
Posts: n/a
 
      02-18-2004
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

 
Reply With Quote
 
 
 
 
Martin Dechev
Guest
Posts: n/a
 
      02-18-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
Janaka
Guest
Posts: n/a
 
      02-18-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting string to a date format tekion Python 4 12-21-2009 10:03 PM
Reading Date Tags and converting them into UTC Format deepak ASP .Net 0 02-14-2008 06:11 PM
The best way to parse a date in a known format Leif Wessman Perl Misc 4 08-29-2004 03:58 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
STL: Converting a string into a list of string blrmaani C++ 4 04-27-2004 09:38 PM



Advertisments