473,218 Members | 1,436 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,218 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 5508
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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.