Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Problem with my format() functions...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
n.net - 25 Apr 2007 03:43 GMT
Due to the much of VBScript inhibition in my early years of website
development,  I exhaustively used the following code in my .NET
console applications.

oLog.setStartTime = Format(Now, "MM/dd/yyyy HH:mm:ss")

This worked fine, when ppl used the code in US.

When the same code was migrated to Singapore, the developers started
to complain about the apparent error that occurs, due to the local
machine settings.

For example a date like 04/25/2007 - the Format() Function which
depends on local machine settings is creating problems.

What is the best practise to get rid of the evil?  Pls advise.
Siva M - 25 Apr 2007 06:52 GMT
Local setting shouldn't really matter because you are giving your own
formatting. Anyway, try this: DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")

> Due to the much of VBScript inhibition in my early years of website
> development,  I exhaustively used the following code in my .NET
[quoted text clipped - 12 lines]
>
> What is the best practise to get rid of the evil?  Pls advise.
n.net - 08 Jun 2007 03:31 GMT
Yeah just check

Dim sTime as DateTime
StartTime = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")

When i try on 08/06/2007 it works. But when I change the date to
22/06/2007.  (The dates I mentioned is 08-Jun-2007 and 22-Jun-2007)

The exception I get is  "Cast from string "06/22/2007 10:27:49" to
type 'Date' is not valid."

Pls advise.

> Local setting shouldn't really matter because you are giving your own
> formatting. Anyway, try this: DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")
[quoted text clipped - 17 lines]
>
> - Show quoted text -
Göran Andersson - 09 Jun 2007 10:26 GMT
> Yeah just check
>
[quoted text clipped - 6 lines]
> The exception I get is  "Cast from string "06/22/2007 10:27:49" to
> type 'Date' is not valid."

The code that you showed can not produce that error message, as you are
not converting a string to a date in that code.

When you parse the string, either specify a culture that uses that date
format, or use DateTime.ParseExact with the same formatting string as
you used to create the string.

Signature

Göran Andersson
_____
http://www.guffa.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.