Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 16th, 2004, 09:20 AM
Authorized User
 
Join Date: Mar 2004
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default get year,month,day,hour...


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

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

2)
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...?

thanks
koby


Reply With Quote
  #2 (permalink)  
Old July 16th, 2004, 04:45 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
objConnection.Open();
DataSet objDataSet=new DataSet("testData");
objDataAdapter.Fill(objDataSet,"testTable");
//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 ....
textBox1.Text=dt.DayOfWeek.ToString();
//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 ....
.
.
.
objConnection.Close();
--------------------------------------------
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
nvarchar(sql)---------->System.string(.NET)
datetime(sql)---------->System.DateTime(.NET)
Money(sql)---------->System.Decimal(.NET)

-----------------------------------
Mahdi
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:53 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.