Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 July 16th, 2004, 09:20 AM
Authorized User
Join Date: Mar 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default get year,month,day,hour...

i have database which contain table with 'Date' column.
(e.g. 17/5/2004 12:00 AM)

i`m interesting to get separately the year, month, day and hour.
there is any method for that?

and finally i want to put every separate catagory in separate column(in new table).
in which type of data should be year, month, hour...?


Old July 16th, 2004, 04:45 PM
Friend of Wrox
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post

Hi koby
this you asked could have too much progrming but I say it to you in a summary manner
in this example I use Orders in Nortwind database and get OrdeDate as a DateTime object
then I use DateTime class for working on OrderDate
//first create you connection an also yor adapter
string strConnection="server=(local);database=Northwind;i ntegrated security=true;";//optional
string strSql="select OrderID,OrderDate,ShipCountry from Orders";
SqlConnection objConnection=new SqlConnection(strConnection);
SqlDataAdapter objDataAdapter=new SqlDataAdapter(strSql,objConnection);
//then I fill mydataset object
DataSet objDataSet=new DataSet("testData");
//here I use ItemArray formy DataRow object ,this property get or set the values for rows through an array
DateRow dr=objDataSet.Tables[0].Rows[0];
object[] t=dr.ItemArray;
DateTime dt=(System.DateTime)t[1];
//for example here t[1] has the value of the first row and second column(OrderDate)in your dataset object
//****there is something important here that the Type of t[1] is DatTime****
//then you can use DateTime properties for getting day,year,months and ....
//here you can make new table and add this variable to it
//even you can change your databse by giving new values to ItemArray property
//and then use Update method in adapter with a SqlCommandBuilder object and ....
you can expand it and do evrything you want
you should know the OrderDate(as type of SqlDateTime)become as type of DateTime when you use ItemArray property
in .NET that means there is a table map between Sqldata type and .NET data type
for example


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding last day of a month John Anthony Access VBA 9 October 6th, 2008 03:27 PM
Exact year month and days mankoti_mankoti2000 Access 1 July 3rd, 2008 10:05 AM
Month and Year to Date on a Report Mitch Access 2 February 20th, 2007 10:23 AM
1st Week-Day of the Month ticktack Classic ASP Basics 2 January 19th, 2004 10:01 AM
Month() Year() questions eon ASP.NET 1.0 and 1.1 Basics 1 October 4th, 2003 04:12 AM

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