How do you reference today's date in Mixpanel JQL API? - mixpanel

event = "function main(){return Events({from_date: '2020-11-01', to_date: ... , event_selectors: [{event:'Search'}]}).groupByUser(['properties.Completion'], mixpanel.reducer.count())}"
What should I put after "to_date" to pull automatically pull today's date?

You can add a variable for today like in the following example:
function main() {
//Get today's date
var today = new Date ( (new Date())).toISOString().split('T')[0];
return Events({
from_date: '2020-11-01',
to_date: today,
})
.groupByUser(['properties.Completion'], mixpanel.reducer.count());
}

Related

how to change datetime format from input using dataTables?

I followed all the tutorials from this link to create a date range filter and it worked but when I tried the results of the input it came out in an incorrect format, https://datatables.net/extensions/datetime/examples/integration/datatables.html
my data table record which was originally of type timestamps, I changed the format using carbon to Y-m-d, which I asked how to change this part of the format
minDate = new DateTime($('#min'), {
format: 'YYYY Do MMMM'
});
maxDate = new DateTime($('#max'), {
format: 'YYYY Do MMMM'
});
the table view
The problem is here:
var date = new Date( data[4] );
It should be :
var date = new Date( data[0] );

Google AppMaker date validation

How to do some date validation here so that when user enter end date less than start date it will prompt error to user? Is there any built in function made by AppMaker? Thanks for sharing!
If you want to limit the input to a data model, you can use the Advanced section of the data model.
You can also achieve data validation through Event section or Data Validation section. Use the the first one to implement small scripts and the second one to hardcode rules into the app.
// date is not a previous date
var date = new Date();
if (widget.value < date) {
alert('Invalid date');
}
// date is not a future date
var date = new Date();
if (widget.value > date) {
alert('Invalid date');
}
// second date is not higher than first date
if (widget.value > widget.parent.descendants.firstDate.value) {
alert('Invalid date');
}

DateRangePicker doesn't recognise carbon date

Using Vue.js ( Vue-Tables https://www.npmjs.com/package/vue-tables ) with laravel.
The data is being succesfully displayed, but the daterangepicker (http://www.daterangepicker.com/) is not sorting at all.
No matter what interval I set, the records won't display. The field is being parsed with carbon to return in needed format
public function getFootageDateAttribute($date)
{
return Carbon::parse($date)->format('d-m-Y');
}
In the js file, I have dateFormat: "DD-MM-YY", filterByColumn: true, dateColumns: ['footage_date'], . When I inspect with vue dev-tools, the field is footage_date: "03-04-2016"
If I hardcode the date as in the example ( https://jsfiddle.net/matfish2/f5h8xwgn/ ) using
// Courtesy of Tomasz Nurkiewicz (Elegant method to generate array of random dates within two dates)
function randomDate(start, end) {
return moment(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
the date is in this format footage_date: "1974-03-27T18:19:40.364Z" and it works.
Pastebin of the full js file http://pastebin.com/6hCe2eQL . Client side http://pastebin.com/xTUcAK98
The footage_date was supposed to be passed as a moment instance, not as a date string, therefore, modifying the ready function did it
ready: function(){
this.$http.get('/api/footage')
.then(function(response){
footages = response.data
footages.forEach(footage => {
footage.footage_date = moment(footage.footage_date)
})
this.tableData = footages
}.bind(this))
}

How to Group Data by week in Linq

I have data starting from date 01/02/2011 and get updated every day.
i want to format data using week starting from date 01/02/2011.
I have entities
public DateTime? MeasurementDate { get; set; }
FORMAT OF DATE:2011-02-01 00:00:00.0000000
Which gives me date from database ..
I want to group data in linq BY Week?
Can You help me?
If you're using Linq-To-Entities you can do:
source.GroupBy(x => SqlFunctions.DatePart("ww", x.MeasurementDate));
Use the GetWeekOfYear method of the Calendar class
var dt = new List<DateTime?> { /*...*/ };
var dfi = DateTimeFormatInfo.CurrentInfo;
var ordered = dt
.Where(x => x.HasValue)
.OrderBy(x => dfi.Calendar.GetWeekOfYear(x.Value, CalendarWeekRule.FirstDay, DayOfWeek.Monday));
Or you can get the date of the first day in the week then group by that date.
To get the date of the first day in the week.
you can use this code:
public static class DateTimeExtensions
{
public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
{
int diff = dt.DayOfWeek - startOfWeek;
if (diff < 0)
{
diff += 7;
}
return dt.AddDays(-1 * diff).Date;
}
}
then you can group by the first date of the week like this:
source.GroupBy(i => i.MeasurementDate.StartOfWeek(DayOfWeek.Monday));
reference

C# linq dates between

I am tring to get a list of dates from my db that will eventually be used to populate a calendar. Each 'calendar event' has a start date & end date, i need to get all dates between & including the start & end date.
i am stuck on the WHERE statement, as i am not sure what to use for this
public List<EventFeed> GetCalendarDates()
{
return (from eventsList in GetEventsList()
select new EventFeed()
{
//EventDate = todo
}).ToList();
}
UPDATE
just to be clear, if i have a calendar event called foobar which starts on 22/08/2010 and ends on 24/08/2010, then i want my list return:
22/08/2010,
23/08/2010,
24/08/2010
thanks
kb
I had to do something similar recently, I used a Func<> to extract the dates from the range and used the result in the linq query.
I have added the same Func to your Linq query below. You didn't specify the name of the object that is returned by GetEventsList() so just replace the EventItem type for the first type parameter in the Func<> with whatever type you need.
public static List<EventFeed> GetCalendarDates()
{
Func<EventItem, List<DateTime>> extractEventDates = eventItem =>
{
var dates = new List<DateTime>();
for (var date = eventItem.StartDate;
date <= eventItem.EndDate;
date = date.AddDays(1))
{
dates.Add(date);
}
return dates;
};
return (from eventItem in GetEventsList()
from eventDate in extractEventDates(eventItem)
select new EventFeed
{
EventDate = eventDate
}).ToList();
}
You mean you want to select all the events that started on or after start date and ended on or before end date!
If yes, then this will help
var query = from #event in events
where #event.Start.Date >= startDate.Date
&& #event.End.Date <= endDate.Date
select #event;

Resources