Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 7th, 2005, 06:58 PM
Authorized User
 
Join Date: Dec 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to raybristol
Default etime format problem again, thanks!

I have a table named News in sql 2000, and I have a column named publishdate with datetime in News table, I read data through dataset like this:

          ' DsNews2 is dataset
           SqlDataAdapter1.FillSchema(DsNews2, SchemaType.Source, "News")
           SqlDataAdapter1.Fill(DsNews2, "News")

               Dim tb2 As DataTable
               tb2 = DsNews2.Tables("News")
               currentID = Integer.Parse(Request.QueryString("ID"))
               Dim drCurrent2 As DataRow
               drCurrent2 = tb2.Rows.Find(currentID)

               Dim pDate As DateTime = drCurrent2("Publishdate")

               Dim pdate As String = pDate.ToString()

i put my project in two machine and I got two different value from pdate, one is like:
2005-11-22 0:00:00
the other one is like:
11/22/2005 12:00:00 AM

I wonder I do I make sure that no matter in what machine, the value of pdate alway to be like the first one: 2005-11-22 0:00:00

by the way, can I remove '0:00:00' part?

many thanks for your help!
:(
 
Old December 7th, 2005, 11:30 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nalla Send a message via Yahoo to nalla
Default

Hi,

   There's nothing wrong in saving the date in SQL Server. But when showing a date field it shows according to the Regional settigs in your machine. That's why you get the date in 2 different formats from those 2 machines.

   To overcome this, format the date before showing it. Use this method to format dates.

Dim dt As DateTime
dt = DateTime.Now
Console.WriteLine(String.Format("{0:D}", dt))

D - paramater to convert the date in to long date format.

Here are some more options for formatting date-time values.

# d: The value is converted to the short date pattern.
# D: The value is converted to the long date pattern.
# t: The value is converted to the short time pattern.
# T: The value is converted to the long time pattern.
# f: The value is converted to the full date-time pattern, including short time.
# F: The value is converted to the full date-time pattern, including long time.
# g: The value is converted to the short date and short time.
# G: The value is converted to the long date and long time.
# M or m: The value is converted to the month day pattern.



 
Old December 8th, 2005, 06:48 AM
Authorized User
 
Join Date: Dec 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to raybristol
Default

thanks very much mate, that's very helpful!!!

 
Old December 9th, 2005, 03:19 AM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to nalla Send a message via Yahoo to nalla
Default

Hi,

UR welcome buddy.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Footer Format Problem rstelma ASP.NET 2.0 Professional 0 August 14th, 2008 04:48 PM
Date Format Problem cyberddindia Classic ASP Basics 2 October 23rd, 2006 01:49 AM
Date Format Problem Scripts82 Access VBA 2 March 13th, 2006 09:36 PM
Problem with format slgknjn Beginning VB 6 2 May 25th, 2005 08:16 AM
Date format problem widad Classic ASP Basics 1 October 15th, 2004 06:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.