i want to set a daily alarm
but i can't convert the Hours and Minutes to Duration to make the Alarm work on time
so is there any Easy way to implement it
i was thinking in converting the time to DateTime and put the year month day etc etc
and then compare between them by Datetime.diffrence() method
like this
Duration duration = DateTime.now().difference(DateTime(DateTime.now().year,DateTime.now().month,DateTime.now().day,hour,minute));
but i think there is an easier way
so if someone can guide me :)
thank u
One option is to try and convert the hours and minutes to a duration something like below:
Duration time = new Duration(hours:2, minutes:3, seconds:2);
Related
Can anyone help me here? I don't have any idea why my code for calculating age is not working. Thank you for the response.
int year = Convert.ToInt32(passportApplicant.DateOfBirth.Year) - Convert.ToInt32(DateTime.Now.Year);
year should be returning a int value already no need to convert it.
also you should be subtracting nows time from the date of birth time (biggertime - smallertime)
your statement should look like this:
int year = DateTime.Now.Year - passportApplicant.DateOfBirth.Year
// 2020 - 2000 = 20 years old
or this gets you the exact year of birth
// this subtracts the passports year, month, and day from the time now
// leaving you with the difference between date born and the time now
int year = DateTime.Now.AddYears(-passportApplicant.DateOfBirth.Year).AddMonths(-passportApplicant.DateOfBirth.Month).AddDays(-passportApplicant.DateOfBirth.Month.day)).Year;
Hope this helps!
Edit:
little side note. try using datetime.UtcNow whenever possible especially when saving to a database. only use the users datetime.now when displaying. it will help you big time down the road as timezone will throw off everything
I do a lot of day-of reporting and one of the things I'm trying to do is compare today's performance to another day. The trouble is I'm trying to comp. to that day to the last full hour. Essentially filter out all data in that comp day that happened after the last completed hour.
I've accomplished this in Tableau but I'd like for this report to be done in Data Studio. Is there a way of using functions to create a custom metric that returns the current hour? If I could get that I could easily use it as a filter for my report.
Thanks for any help.
Here's what the solution looks like in tableau:
IF [Session Hour (int)] <= [Current Hour]
THEN
[Revenue GA]
END
And:
DATEPART('hour', Now())-4
I was able to filter to the current hour by
a) making a calculated field to figure out the minutes difference between now and the data
minutes_before_now = datetime_diff(current_datetime(),the_time,MINUTE)
and b) filtering the data where this field was < 60
My advice would be to create a filter inside a date range, p.e.
And then you can choose the comparison range within the primary date range.
That's what I'd do, if I understood your question.
How to stop previous interval(elapsedEvent) and start new interval(elapsedEvent) timer in C#.
Ex: I had interval with one hour with interval(elapsedEvent) , later user changed to two hours with interval(elapsedEvent).
While I tried to change one hour to two hour interval (elapsedEvent), it is coming for both one and two hours as well.
Need to change the interval (elapsedEvent) of timer what I given.
i m using Session("date_time") for storing login date and time and during the time of logout i need to store the duration of the time only and for that i m using a login_duration as integer as login_duration = (Session("date_time").ToString - Now.ToString("hh:mm:ss"))... but its not working properly.. Help me plz to solve the problem
For time : TimeValue(Now)
For date and time : NOW
About the format, check here
I want to use a asp.net drop down to present the user a delivery date on checkout. What I'm not sure about is how to get the specific dates. What the user should see and be able to select in the drop down is the next Monday and Tuesday for the next two weeks. Any help would be appreciated.
thanks.
The simplest solution is to use the DateTime.DayOfWeek property (http://msdn.microsoft.com/en-us/library/system.datetime.dayofweek.aspx).
You start with getting today's date, or, if today is Monday and you can't deliver for two days, so the next delivery will be a week Monday, then start with tomorrow. I am not certain how you would handle if I order tomorrow could I get a delivery date for the next day, so I would need that clarified.
Get the day of the week, starting with either today or tomorrow, extracting it from a specific date as explained here:
http://msdn.microsoft.com/en-us/library/system.datetime.dayofweek.aspx
If it isn't Monday or Tues then just determine how many days you need to reach Monday or Tuesday, then add that number of days and get that date, and then just add seven and get the date.
I would prefer to let .NET determine the date of seven days from now, as you may change month or years.
That is the basic approach. If you get stuck when trying to implement it, I would suggest some code so we can help you determine where you got stuck.
There are other approaches, but this is probably the simplest to understand and implement.
Here's a pretty simple suggestion using a lot of LINQ:
private void LoadDeliveryDays(int period)
{
DateTime[] days = Enumerable.Range(1, period).Select(i => DateTime.Today.AddDays(i)).ToArray();
DropDownList1.DataSource = (from d in days where d.DayOfWeek == DayOfWeek.Monday | d.DayOfWeek == DayOfWeek.Tuesday select d.ToString("dddd dd-MM-yyyy")).ToArray();
DropDownList1.DataBind();
}
You probably want to change the d.ToString("dddd dd-MM-yyyy") and/or what value is actually used in the dropdown.