I want to know when is the New Month. So that I can do some operation
like, copy last month data [eg. Category.Title] from last month [Jan] to the new month [Feb].
Month Catagory
===== ========
Jan => Category.Title
Feb => New Category.Tile (copy based on Jan's data)
How do I construct the logic to detect that Today is a new month (so that I can preform the copy operation)?
Basically, I want to detect when is the New Month begin?
If all you need is the logic to check if today is the first day in a month, you can use the following code.
var d:Date = new Date();
if (d.date == 1) {
//today is the first day in a month
}
Depending on where/when you're doing this however, it may not have the effect you desire. Without more information, I can't really help you there.
You should employ this fabulous logic found on the provided link and go from there. Pretty much you need to find out if current date of the month. Lets say if today is the 15th of April, you will then need to find out how many days are there in April, 2012, and where does the 15th of April fall. And then have a counter count the remaining days until the new month (May) begins. You also want to make sure that you are checking for the leap year. This link also has a function that checks for the leap year. I am giving you a high level idea to go about getting what you trying to.
http://www.electrictoolbox.com/javascript-days-in-month/
Thanks a lot.
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 am using fullcalendar.io and I realized that if I create a new event in the month view, dragging across one or more days, it returns a timestamp for the end date which is later rendered as 12 am of the day after while it should be logic that a function date("what-ever-format", timestamp) returns 12 pm of the current day, or, in any case, not the following day.
Any idea how to fix this???
We are using Jira for a Kanban board and our manager wants a weekly report of all the changes in the last week.
Can I generate this from Jira?
You can use simple date calculation to retrieve Issues that have been updated in the last week
This will return all issues that were updated since the beginning of the current week.
updatedDate > startOfWeek()
If you want to see the last 7 days from the current date, use
updatedDate > startOfDay(-7d)
I have a view filled with content of stuff that needs to be done every month.
I already have it set up to show everything that fits that parameter, I have one more thing i want it to filter by:
I want it to be able to show only things that have not been edited in the current month. This does not mean within a month.
If today is June 02 I want to
see something that was updated may 31
not something edited june 01
I am able to set it by an exact day, but i don't want to have to change that every month.
I am able to set it by a set amount of time(-1 month), but this will do it within a month instead of within the month
Remove your filter and add a contextual filter: Content: Updated month - Date in the form of MM (01 - 12). & select the option Provide default value to Current Date. This will make sure your view gets content from the current month & not from within a month range.
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.