Breeze EntityManger executeQuery spans february dates by a month i.e. march.This happens only when system date on which browser is running is set to 30th of any month.
Say its 30th of April 2017** as date of my machine**.
I have 22-feb-2017 as ReviewDate in my database.
When i run below statement:
var eq = breeze.EntityQuery
.from("Reviews")
.where("ReviewId", "==", "a0544246-bb38-46ff-ba0c-eef16a135378");
em.executeQuery(eq)
.then(function (data) {
data.results[0].ReviewDate // Gets output as **22-march-2017**
Related
so I have this query that pulls all the data from the previous month but I would like it to pull the previous 6 months
=query(Insiders!A4:L,"Select * where month(C)=month(now())-1",1)
Taking the current month as July, if you want to display results where the date in Col C is in Jan 2021 to June 2021 inclusive, then try this:
=arrayformula(query(Insiders!A4:L,"Select * where C>= date '"&text(eomonth(today(),-7)+1,"yyyy-mm-dd")&"' and C< date '"&text(eomonth(today(),-1)+1,"yyyy-mm-dd")&"' ",1))
Currently (at 10/7/2021), text(eomonth(today(),-7)+1,"yyyy-mm-dd") = 2021-01-01
text(eomonth(today(),-1)+1,"yyyy-mm-dd") = 2021-07-01
These are the two date search ranges.
You can alter the eomonth() function parameters -7 and -1 to move the months into a different period.
try:
=QUERY(Insiders!A4:L, "where month(C)+1="&MONTH(TODAY()), 1)
I have a Date variable with a person's date birthday. I would like to know how many days remains before this person next birthday. It should be calculated from today date to current year birthday date.
How can this be done with Swift? Also it will be great to consider February 29 in leap years.
To the guys who tried to close this: This is about birthday which has totally different rules from days.
Birthdays are complicated. Your birthday was the date of the moment when you were born, in the timezone where you were born. Considering that Samoa = UTC+14 and Baker Island = UTC-12, it is possible that people born at the same moment in time have birthdays that are two days apart.
So to store somebody's birthday, not the moment of birth, you either store year/month/day, or if you want to store it as a point in time, you store the beginning of that day in UTC, with the understanding that this is to specify a day, and must not be converted to local time.
Now when does your birthday repeat? If the person is born on D/M/Y and D/M is not February 29th, then the next birthday is either D/M/current year or D/M/next year. It is D/M/current year if that date is in the future, otherwise D/M/next year.
If the person is born on February 29th, then you have to determine when officially the next birthday is if the year is not a leap year - this will be February 28th or March 1st, depending on which rules apply.
We also need to clarify what "number of days" means. If my birthday is on April 1st, and now it is March 31st, one second to midnight, my birthday will be one second from now. However, I will assume that the result is supposed to be "one day from now".
So here is the algorithm:
Step 1: Find day/month/year when the person was born.
Step 2: Determine the current time, and convert it to local day/month/year. Determine the current time only once to avoid problems if this calculation is done nanoseconds before midnight.
Step 3: Determine the year when the birthday repeats: If day/month of birthday is greater than current day/month, then the year when the birthday repeats is the current year, otherwise the next year. This is also correct if the birthday was on Feb. 29th.
Step 4: Determine the day/month when the birthday repeats: This is the same as the day/month of the birthday, unless the birthday was on Feb. 29th and the year when the birthday repeats is not a leap year. In that case, the birthday repeats on Feb 28th or March 1st, depending on which rules you decide to apply.
Step 5: Convert the current day/month/year + 12 hours to UTC. Convert the date when the birthday repeats + 12 hours to UTC. Calculate the difference in seconds (which the OS should do for you). Divide by 86,400, then round to the nearest integer. The "+12 hours" and "round to nearest integer" make sure that you have no problems with daylight savings time, leap seconds etc.
Writing this code in Swift or any other language should be no problem.
It depends on what you are looking to use the days value for but here is a small function that will return a Double describing the amount of days until a given Date. Martin R gave a really good answer here and my answer is mainly based on theirs with a little bit of documentation added.
/// This function takes a `Date` parameter and returns an `Int` describing how many days away the `Date` is into the future (accounting for leap years by making 2/29 dates land on 3/1 in non-leap years).
/// - Parameter date: The `Date` object to be evaluated.
func daysUntil(birthday: Date) -> Int {
let cal = Calendar.current
let today = cal.startOfDay(for: Date())
let date = cal.startOfDay(for: birthday)
let components = cal.dateComponents([.day, .month], from: date)
let nextDate = cal.nextDate(after: today, matching: components, matchingPolicy: .nextTimePreservingSmallerComponents)
return cal.dateComponents([.day], from: today, to: nextDate ?? today).day ?? 0
}
I am using Parse within a Swift App.
How do get the SlotName and appropriate day field(s) on records where Monday, Tuesday, Wednesday, Thursday and/or Friday equals "username".
Could you do this in three steps:
Retrieve all records where:
Monday = Username
Tuesday = Username
etc.
Then check to see what the SlotName is for the given record.
Then for the returned record, iterate through to see if:
Monday = Username
Tuesday = Username
etc.
Where a record's value for a given week day is True (for example: Monday = Username), then put this into an array. This would give you a list of appointments and the times of the said appointments for a given username.
I am trying to get week number(1,2,3,4,5) with in the month from Jquery UI datepicker. I googled and get the code of iso8601Week but not normal week number.
Kindly Help
This should give you close to what you want, although I've only smoke tested it and there are probably some more edge conditions that need to be addressed.
I basically took the iso8601Week of the first day of the month, and subtracted it from that of the selected date. That works as is for most dates, but ISO 8601 puts days before Jan 4th in the previous year if they fall before Thursday. That's the reason for the % 52.
The code assumes an input called testDate and a label called label1:
$('#testDate').datepicker({
onSelect: function(dateText, inst) {
var d = new Date(dateText);
var d1 = new Date(d.getFullYear(), d.getMonth(), 1)
var x = $.datepicker.iso8601Week(d) % 52;
var y = $.datepicker.iso8601Week(d1) % 52;
$('#label1').text(x-y+1);
}
});
I left in all the variables with partial results in them so you could tinker around with the values. This code assumes that the week begins on Monday (which is the ISO 8601 standard), and that partial weeks before Monday are week 1. So, if the month begins on a Monday, the first Monday is in week 1, and if the month begins on any other day, the first Monday is in week 2. Which looks a bit strange if the 2nd of the month is on Monday and also in week 2, but if you don't like that, you'll have to spend some time deciding in detail what you do like.
I have an Array with some month and year.for ex array {Jan 2015,feb 2015, june 2015, september 2015}. I want to get the index of the current month and am getting it. If there is no current month, then i want to get the upcoming recent month.In the above example i want to get the index of september 2015.
Help much appreciated.
Below is the code to get the index of the current month.
if ([titleMonth isEqualToString:currentMonth])
{
indexNumber=[[self.dataByMonth valueForKey:#"title"]indexOfObject:currentMonth];
}
Here am getting the current month from NSDate.
Create NSDataComponents
First, you need to fill the array with NSDateComponents objects. Look at this method in particular.
For example. To create NSDateComponents for current month.
NSDateComponents *dateComponents = [[NSCalendar currentCalendar]components:(NSCalendarUnitMonth | NSCalendarUnitYear) fromDate:[NSDate date]];
Then fill up your array with these components.
Loop through the array until the current month and year is equal or lesser than the looping month and year. If they are equal, you have your current month. If its lesser, the item in the array is the next month/year.
Would this work?
Here is a rough sample code
for(NSDateComponents *components in arrayOfMonths)
{
if(currentMonth.date == components.date)
NSLog(#"current month is on the list");
else if(currentMonth.date < components.date)
{
NSLog(#"this is the next month on the list");
break;
}
}
if your first array is {Jan 2015,feb 2015, May 2015, september 2015}. Keep another array with all the months {Jan 2015,feb 2015,Mar 2015,..... Dec 2015}.
If current month is June and it is not there in 1st array. Take the next element in 2nd array and check with the 1st array. So, check July is there in 1st array and continue this process until you find match. So, you will get September 2015.
Don't know if this is what you wanted.