Does anyone know how to retrieve data by month using Mongodb query? For example, if I only want to retrieve the date range for the past month, or for the past two month, how do I do that? I see examples for getting data for the last N day (e.g for past 5 days using this new Date(new Date().setDate(new Date().getDate()-5) or N hours, but not seeing examples for only retrieving data for the last N month. Thanks,
Yes, You can retrieving data based on month like this.
new Date().setMonth(new Date().getMonth()-1) or N months.
And you can also get past month start and end date using moment like this.
moment().subtract(1,'months').startOf('month').format('YYYY-MM-DD')
it will provide previous month start date i.e 2021-01-01
moment().subtract(1,'months').endOf('month').format('YYYY-MM-DD');
it will provide previous month end date i.e 2021-01-31
Related
I have a requirement where I am giving Date of Birth from tRowGenerator. I want to loop till the current year i.e. from date of birth to current year and display values in tlogrow.
I'm able to print Years, Months, seconds, M seconds difference using TalendDate diff function but not in a loop.
I tried figuring out a solution but could not succeed. Can anyone help me out?
Total result in 1 log:
I have a data set spanning 2 years and is updated daily, created a dashboard to give a view of incidents by date group. I have created a parameter using date trunc for Day/Week/Month/Quarter/Year. This is in Tableau.
I am trying to get the parameter to show a Week to date, Month to date and so on view. IE if on Weds 15th Dec I selected the weekly view, it would only show data for every week in the data set for Sat-Weds (My weeks go Sat-Fri) or the monthly view every month between 1st-15th
Ideally I am wanting this as a simple parameter for a drop down menu, I can do the week to date stuff as a rolling sum restarting every week in a separate table, but for ease I just need a date group function that will allow to do this.
Any suggestions would be appreciated.
Cheers
Pete
The solution is 5 parts:
Date Part Parameter
Max date [Max Date]
Dynamic date part of the Max date [Dynamic Date Part Max]
Dynamic date part of the historical dates [Dynamic Date Part]
Filter those date parts <= the Max date [Dynamic Date - Lass than Max]
Date Part Parameter
Max Date
This is the calculation you'd use with your dataset to find the max date.
{ MAX([Order Date]) }
In order to create a good example, I'm going to set my Max date to a specific date the falls in the middle of a week, in the middle of a month and middle of the year. I'm going use June 13th, 2018 as my Max Date.
So, if you want to follow along you can use the below date as your max date. You can also use this data set if you'd like.
DATE(#2018-06-13#)
Dynamic date part of the Max date
DATEPART([Select Date Part], [Max Date])
Dynamic date part of the Historical dates
DATEPART([Select Date Part], [Order Date])
Filter on Historical dates parts <= the Max Date
[Dynamic Date Part] <= [Dynamic Date Part Max]
Now that we have all the pieces we need let's check to make sure they are working as we would expect.
Looks like we're seeing all the days of the month that are <= the 13th.
When we change it to Day of the Week we see only the days of the week <= the 4th day of the week which is Wednesday when the week starts on Saturday.
Now let's calculate the running sum of sales along our dynamic date part to better help you with your example.
Drag the measure you want to calculate the running sum onto the label, then create a quick table calculation. We'll next need to edit this table calculation as so.
You'll then see your calculation working as you would expect.
Hope this was helpful. Happy vizzing!
Here I'm saving the date range using golang. Suppose we have to save the all monday comes between the range of the 1-may-2018 to 14-july-2018.
How we will find all the monday between these range using golang and on the other hand we have set the start_time (8:00 A.M.) and the end_time (6:00 P.M.) of the first two coming monday in the database but on the third monday we have a change in the schedule that there is a time change like start_time (9:00 A.M.) and end_time (5:00 P.M.). Then how I will make my database to make this situation in practically using the golang.
Can Anybody help me for this to solve this solution. I made a database for and I do ppr work on it and make some fields shown below:-
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Start_hours (int)
Start_minutes (int)
End_hours (int)
End_minutes (int)
Start_date (timestamp)
End_date (timestamp)
How I will select monday between the selected range and how will I do the situation I explained above can anybody give guidance to me to make this situation easier. Thank you if this is a basic question then I'm really sorry.
I'd make something like this.
Find the first Monday date from the date range (see for example How do I get the first Monday of a given month in Go?
Mondays happen every week, so you can easily find the rest of dates by adding 7 days till the end date
Store all the Monday dates you found with the start and end times
I wouldn't bother with hours and minutes as you can easily get them from the timestamps in Go. Here is the simplified DB structure I would make
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Date (timestamp) // the actual date
Start (timestamp)
End (timestamp)
You don't need any more fields. You can get the day of the week (Day (string) in your structure, e.g. Monday) from the Date field too, but I believe if you want to query the collection by different days, this might speed things up, but be careful if you need to adjust for time zones. If you work with more than one, then store everything in UTC and you may have an extra filed Timezone, cos a date could be Monday for one zone and Sunday for another.
So, the Schedule will hold weekdays and start and end times for each of them. I'm not sure if you need to store initial date ranges, the Schedule collection will hold that range as well, form the first record to the last one. In my mind, I'd initially populate the collection with a given date range, then later on, I can modify it by adding new days, or deleting them.
When you query this collection with some start and end date range for the Date field, if your first result comes newer than 7 days from the start, this means you miss 1 or more entries from the start. If the last result comes older than 7 days from the range end, this means you miss some entries prior to the range end.
There is nothing specific to Go, in my opinion, Go works well with dates and you don't need any special date structures in your DB.
I have a Grails Domain that contain two date feild
Date updated
Date created
I want to count number of rows based on updated time with respect to month or hour or year. How can I do that. The methods showed on Internet does not work. I am using grails version 2.4.4.
Update:
Example
I have a domain that contain four feids
Date Created
Date updated
Long id
Long idx
I want to find how many idx is there in every group when i group by hour. Like there can be 5 in 12h and 6 in 13th hour... so on.. How can i find those.... My comaparison is not fixed. It can be changed to mont or year... In year it will show the number of idx in each year. in month it will show the number of idx in each month..
How can I do this with grails...
You can use where detached query:
DomainClass.where { year( updated ) == 2014 }.count()
Similarly, hour(), minute() etc.
Refer WHERE queries for details.
I have this date in my history table with field dtEnd="2012-07-10 11:07:00"
and i want to retrieve July 10 and Last Tues both from this date separately.
Can anybody suggest a query for doing this?
Thanks.
While surfing, I came to know that it is not possible to get Month and date name instead you have to use your logic for that.
I got the solution, I am getting month and date with:
Select strftime('%m-%d','dtend')'Date' from history
And then I am extracting month and day number separately and then passing that month number to my own function with switch case to give month name.
That's it and I got my solution.