473,396 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Timespan Problem

Hi all i have just begin csharp have a problem in saving time in
database

I have to comboboxex in form one containing hours from 0 to 23
and another containig minutes from 0 to 59
the problem is saving it in to the database

I want to save only the time in to the database but i dont know how to
convert it
wether to use timespan to use datetime datatype
please help

Dec 13 '05 #1
7 5514
jack <ga**********@gmail.com> wrote:
Hi all i have just begin csharp have a problem in saving time in
database

I have to comboboxex in form one containing hours from 0 to 23
and another containig minutes from 0 to 59
the problem is saving it in to the database

I want to save only the time in to the database but i dont know how to
convert it
wether to use timespan to use datetime datatype


It sounds like DateTime would be a better fit for you. I don't know
whether most databases even have a TimeSpan concept. Of course, you
could just store hours*60+minutes as an integer...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 13 '05 #2
I have made it
This is what i found perfectly working
ha ha ..
int year = Convert.ToInt32 ( System.DateTime.Now.Year.ToString ());
int month= Convert.ToInt32 ( System.DateTime.Now.Month.ToString
());
int day = Convert.ToInt32 ( System.DateTime.Now.Day.ToString ());
int hour = Convert.ToInt32 (cmbHour.SelectedItem.Text.ToString ());
int min = Convert.ToInt32 (cmbMin.SelectedItem.Text.ToString ());

DateTime mydate = new DateTime(year,month , day , hour , min ,00);

Dec 13 '05 #3
jack <ga**********@gmail.com> wrote:
I have made it
This is what i found perfectly working
ha ha ..
int year = Convert.ToInt32 ( System.DateTime.Now.Year.ToString ());
int month= Convert.ToInt32 ( System.DateTime.Now.Month.ToString
());
int day = Convert.ToInt32 ( System.DateTime.Now.Day.ToString ());
int hour = Convert.ToInt32 (cmbHour.SelectedItem.Text.ToString ());
int min = Convert.ToInt32 (cmbMin.SelectedItem.Text.ToString ());

DateTime mydate = new DateTime(year,month , day , hour , min ,00);


Why are you converting the year, month and day from an int to a string
and then back again? Similarly, why are you calling ToString() on
SelectedItem.Text (which already returns a string)?

Why not just do:

int hour = int.Parse (cmbHour.SelectedItem.Text);
int min = int.Parse (cmbMin.SelectedItem.Text);

DateTime myDate = new DateTime (DateTime.Now.Year,
DateTime.Now.Month,
DateTime.Now.Day,
hour,
min,
0);

Alternatively:

DateTime myDate = DateTime.Today.AddHours (hour).AddMinutes(minutes);

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 13 '05 #4
o o
Thanks this is good , as i said i m a i have just started learning
thanks for the short cut

Thanks once again...

Dec 14 '05 #5
what is the difference between int.parce and toint32() function
(converters)
just wanted to know
Thanks for the help

Dec 14 '05 #6
jack <ga**********@gmail.com> wrote:
what is the difference between int.parce and toint32() function
(converters)
just wanted to know


int.Parse will throw an exception if you give it a null reference.
Convert.ToInt32(string) will return 0.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 14 '05 #7
Thanks for the reply Jon Skeet

I had just experimented this
Thanks once again

Dec 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dirk Reske | last post by:
hey, when I do: TimeSpan ts = TimeSpan.FromTicks(System.Enviroment.TickCount); ts.ToString(); I get something like this: 00:00:00.2381474 but I want to see, how many hours,...
2
by: Jeff Shantz | last post by:
Hello, I'm developing a large statistics application for a call center. It often needs to calculate time spanning over months. For example, an agent's total talk time within 30 days. Since an...
2
by: DWalker | last post by:
In Visual Studio (Visual Basic) .NET 2002, I noticed that this: Dim Elapsed as DateTime = Now - Now gives a "compile time" error (error in the IDE), saying that the '-' operator is not...
2
by: ucasesoftware | last post by:
i translate a C# funtion to VB.NET and i have this : Shared Function isAllDay(ByVal ap As Appointment) As Boolean Return ap.DateBegin.TimeOfDay = TimeSpan.Zero AndAlso ap.DateEnd.TimeOfDay =...
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
2
by: Rob | last post by:
I was just getting started with TimeSpan and I get a error in my first line of code... I write... Dim ts as TimeSpan And Intellisense gives me an error "Type Expected" I did notice that...
5
by: prasanta.bhowmik | last post by:
Hello, I created a object of TimeSpan only with minute and expected the result in hours and minute, but its returning wrong result. My Code is : TimeSpan timeSpan = new TimeSpan(0,2400,0);...
5
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: ...
4
by: Massimo | last post by:
Hi to All, i'm using C# in .NET 2.0 and i have a DataTable A with a column of type TimeSpan used to store HOUR info. I'm trying to filter my DataTable A selecting only rows that have the column...
2
by: shapper | last post by:
Hello, I have the following: boxStat = new BoxStat { BoxCount = database.Boxes.Count(), SinceLastCreate = (DateTime.Now - database.Boxes.Max(b => b.CreatedAt)).Days ?? 0 };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.