Subtract timespan.min from timespan.today [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a datatable column type TimeSpan. how would you subtract the Min of this timespan column from current time ? Appreciated.
Column name "Hours"

Calculate the minimum value :
var min = table.AsEnumerable()
.Min(r => r.Field<TimeSpan>("Hours"));
Subtract it from current time:
var newTime = DateTime.Now - min;

Related

how to change date at a specific time [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I m very new to C# and have some issue. I've a project where I need to change the date when School starts at 0700 am only not at 1200 am. I tried something like this but doesn't work
System.TimeSpan timeDiff = TimeSpan.FromHours(.292);
DateTime presentDate = (Convert.ToDateTime(sysDateTime)).Subtract(timeDiff);
I used this way in VB6 where I just substract .292 from current dateTime to change the date at 0700 am instead of 1200 am but dont know how do I achieve the same in C#.
You can try with
DateTime d = (Convert.ToDateTime(sysDateTime)).Subtract(new TimeSpan(5, 0, 0));

C# DateTime The last 1 days of each month [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Yesterday. Here we subtract one day from the current day. We do this by adding -1 to the current day. This is necessary because no "Subtract Days" method is provided.
Note:
The example was run a few years ago. The output will naturally vary depending on the day you run it.
And:
DateTime.Today is always set to the machine's local time, which depends on the current system.
public DateTime GetLastDayOfMonth(int year, int month)
{
month += 1;
if (month>12)
{
month = 1;
}
return new DateTime(year, month, 1).AddDays(-1);
}

how to convert decimal value into int in c# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have decimal values in the database. I want to show the decimal value in it. How to convert decimal values into it.
int vatprice;
dt.Load(cmd.ExecuteReader());
vatprice = Convert.ToInt32(dt.Rows[0][5].ToString());//getting error here
As per your requirement, round decimal up to 2 place using following way :
1) Use Math.Round().
var vatprice= Convert.ToDecimal(Math.Round(dt.Rows[0][5], 2));
2) second way is
var vatprice=Convert.ToDecimal(dt.Rows[0][5].ToString ("#.##"));

c# determine how long the computer has been to sleep for & then convert this to an integer [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How do I convert this the time the computer has been to sleep for (here called 'offTime') into an integer (in terms of minutes)?
`DateTime timeOnSleep = DateTime.Now;`
`Application.SetSuspendState(PowerState.Suspend, true, true);`
`DateTime timeOnWake = DateTime.Now;`
`System.TimeSpan offTime = timeOnWake - timeOnSleep;`
TimeSpan time = timeOnWake - timeOnSleep;
var hours = time.TotalHours;

How do I format a string? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a string "5-13-2013"
I want to make it look like "051313"
All three fields (month,day,year) must have 2 digits, if it only has one , I need to add a zero in front
any easy way to do this?
You can convert your datetime to multiple formats like
string date = yourdateTime.ToString("dd/mm/yyyy");
string date = yourdateTime.ToString("dd/mm/yyyy HH:mm");
string date = yourdateTime.ToString("dd/mm/yyyy HH:mm:ss");
string date = yourdateTime.ToString("mmddyy"); // your desired
To know what these mean you need to read here.

Categories