473,657 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get minutes count

Hello.

I have a string with some time in it, for example "13:59".
How can I get how many minutes is in it?
Like this: "1:30" contains 90 minute.
Can anybody show me some example?

Tank you.
Nov 16 '05 #1
6 2577
If the format is always like that, then could simply parse on the colon and
convert each part to an integer. Then multiply the first one by 60 and add
the result to the second one.

"David" <da*********@ho tmail.com> wrote in message
news:eu******** ******@TK2MSFTN GP14.phx.gbl...
Hello.

I have a string with some time in it, for example "13:59".
How can I get how many minutes is in it?
Like this: "1:30" contains 90 minute.
Can anybody show me some example?

Tank you.

Nov 16 '05 #2
David wrote:
Hello.

I have a string with some time in it, for example "13:59".
How can I get how many minutes is in it?
Like this: "1:30" contains 90 minute.
Can anybody show me some example?

Tank you.


You could try the following C# snipped:

private string GetMinutes(stri ng s)
{
string[] temp = s.Split(':');
int minutes;

if (temp.Length == 2)
{
minutes = Int32.Parse(tem p[0]);
minutes *= 60;
minutes += Int32.Parse(tem p[1]);

return minutes.ToStrin g();
}
else
return "Wrong format";
}

This code is far from ideal and works for time strings like "9:30" or
"1:00" so you will need to take measures to handle special cases like
"2", which could mean "two minutes" or "two hours". Hope this helps.

Regards

Catherine
Nov 16 '05 #3
Thank you very much for helping.
Can you help me in one more situation...
How do I get time string from minutes?
Like: 90 convert to "01:30".

"Catherine Lowery" <cl*****@imap.c c> wrote in message
news:32******** *****@individua l.net...
David wrote:
Hello.

I have a string with some time in it, for example "13:59".
How can I get how many minutes is in it?
Like this: "1:30" contains 90 minute.
Can anybody show me some example?

Tank you.


You could try the following C# snipped:

private string GetMinutes(stri ng s)
{
string[] temp = s.Split(':');
int minutes;

if (temp.Length == 2)
{
minutes = Int32.Parse(tem p[0]);
minutes *= 60;
minutes += Int32.Parse(tem p[1]);

return minutes.ToStrin g();
}
else
return "Wrong format";
}

This code is far from ideal and works for time strings like "9:30" or
"1:00" so you will need to take measures to handle special cases like "2",
which could mean "two minutes" or "two hours". Hope this helps.

Regards

Catherine

Nov 16 '05 #4
"David" <da*********@ho tmail.com> wrote:
I have a string with some time in it, for example "13:59".
How can I get how many minutes is in it?
Like this: "1:30" contains 90 minute.


Assuming your string always has hours and minutes, this will work:

string sTime = "1:30";
string[] sHoursMins = sTime.Split(new string[] { ':' });
int iHours = Convert.ToInt32 (sHoursMins[0]);
int iMinutes = Convert.ToInt32 (sHoursMins[1]);
int iTotalMinutes = iHours * 60 + iMinutes;

However, your code might be clearer if you use the TimeSpan class
instead.

P.
Nov 16 '05 #5
David... A good general approach is to look for an OO solution. If you
cannot find an OO solution in the framework, then consider writing your
own class. There is a class in the framework that encapsulates the
concept of time and has a built in method to return the number of
minutes.

TimeSpan ts= new TimeSpan(0,1,30 ,0);
System.Console. WriteLine(ts.To talMinutes);
Output: 90

Regards,
Jeff
I have a string with some time in it, for example "13:59".

How can I get how many minutes is in it?
Like this: "1:30" contains 90 minute.
Can anybody show me some example?<

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6
David wrote:
Thank you very much for helping.
Can you help me in one more situation...
How do I get time string from minutes?
Like: 90 convert to "01:30".

"Catherine Lowery" <cl*****@imap.c c> wrote in message
news:32******** *****@individua l.net...
David wrote:

Hello.

I have a string with some time in it, for example "13:59".
How can I get how many minutes is in it?
Like this: "1:30" contains 90 minute.
Can anybody show me some example?

Tank you.


You could try the following C# snipped:

private string GetMinutes(stri ng s)
{
string[] temp = s.Split(':');
int minutes;

if (temp.Length == 2)
{
minutes = Int32.Parse(tem p[0]);
minutes *= 60;
minutes += Int32.Parse(tem p[1]);

return minutes.ToStrin g();
}
else
return "Wrong format";
}

This code is far from ideal and works for time strings like "9:30" or
"1:00" so you will need to take measures to handle special cases like "2",
which could mean "two minutes" or "two hours". Hope this helps.

Regards

Catherine

The following solution is one of the easiest imaginable an has some
drawbacks but works as expected:

private string GetTimeString(s tring s)
{
string result = String.Empty;
int minutes = Int32.Parse(s) % 60;
int hours = (int)Int32.Pars e(s) / 60;
result = hours.ToString( ) + ":" + (minutes.ToStri ng().Length == 1 ?
"0" + minutes.ToStrin g() : minutes.ToStrin g());
Console.WriteLi ne("Minutes: {0}", result);
return result;
}

To get the minutes I simply did a modulo and to obtain a value for the
hours I divided the same value by 60 and cut off the decimal part by
casting it to an int. Furthermore I fetched the length of the resulting
string to format it properly. If you pass a string, say "65", you will
get "1:05" instead of "1:5". This might not be the best solution but may
give you an idea how things work.

Regards

Catherine
Nov 16 '05 #7

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

Similar topics

4
4184
by: hupjack | last post by:
I finally joined the millions of cell phone users out there. I'm the 2nd phone on what is now a family share plan. (Our two cell phones use minutes from a central 400 minute peak time pool.) Looking at the verizon wireless website, minutes used are displayed only as two different totals for our 2 phones. Dialing in from a phones to check remaining minutes, the minutes are presented the same way, broken down by each phone but not...
2
2451
by: Michelle | last post by:
Hello! I have an .aspx web form in an ASP .NET application that I need to Auto Save every 15 minutes. Could anyone provide examples of client-side Javascript to count down the 15 minutes? Thank you for your help! Michelle
2
32866
by: James P. | last post by:
Hello, In my Access report, I have a minutes field in the detail line. How do I convert that minute to hour and minute. The problem for me now is if I take the minutes, say 75 divide by 60, it gives me 1.25; or 90/60 = 1.50. These are not what the user wants. They want to have hour and minutes, say 75 minutes, needs to convert to 1.15 (1 hour 15 minutes); or 90 minutes to 1.30, and so on.
2
5575
by: Robert Mayer | last post by:
Hello! I would like to count 15 Minutes (in this style: 15:00, 14:59, 14:58 ...) backwards with a Timer and want to show it on a Label. The Time is displayed correctly (15:00), but nothing happen. Did I forgot something?? int Minutes = 15;
15
10984
by: dee | last post by:
Hi, What is the maximum number of minutes for Session timeout that I can specify in web.config? Thanks. Dee
3
2454
by: Vidya | last post by:
Hi, I want to get the count of rows per each 20 minutes, is that possible? Is there a date function or any other function that I can use in Group by clause, which will group the data of every 20 minutes and give me the count? Thank you. Vidya
8
8113
by: Stefan Barlow | last post by:
On IIS 6, I've disabled idle timeouts and any app pool recycling other than the 29 hour timed recycle. I've disabled both on the app pool itself and on all app pools at the server level. I've restarted IIS as well. After 20 minutes of inactivity, sites are still being shut down. Going by the logs, there is a time stamp if the idle time is greater than 18 or so minutes.
2
12309
by: mar10 | last post by:
i have TIME WORKED stored as minutes - I'd like to convert this to days,hours,minutes. I'm currently converting to hours and minutes but have not had success adding the days portion to the formula below. Any direction is greatly appreciated. thanks
4
2651
by: fpjkaba | last post by:
How to count online users and guests for the last 30 minutes on my site? I'm using mysql, php and apache for windows. Thanks.
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.