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));
Related
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 2 years ago.
Improve this question
I am not a C# programmer, but was given an API where part of their code requires generating of a Timestamp but example was given in C# so I am stuck as to how I can get the same results in PHP. Can someone here help to show me how this code would be in Php?
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
DateTime dtNow = DateTime.Parse(DateTime.Now.ToString());
TimeSpan toNow = dtNow.Subtract(dtStart);
string timeStamp = toNow.Ticks.ToString().Substring(0, timeStamp.Length - 7);
I am sort of able to get the first 2 line into PHP, but 3rd line onwards, I am lost.
<?php
$date = new DateTime(); // OR new DateTime('2000-01-01');
$timestamp = $date->getTimestamp();
?>
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);
}
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;
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;
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.