How to get number of days between two dates? - reactjs

I have a property created_at which stores Date and time of users that sign in for. So using Moment.js I want to get the number of days from "latest date" -"created_at".
moment(new Date()).diff(tag.created_at)

You should be able to get the number of days between to dates a and b as follows (using Moment):
a.diff(b, 'days')

Related

Can time series settings in Google Data Studio change depending on date format?

I have a table with column "date" in YYYY-MM-DD format HH:MM:SS:MMM (2015-01-27 11:22:03:742). I'm trying to make a time series with the dimension of month/year grouping, to display the total number of records by period.
Settings:
period dimension: date (type: date and time)
period: date (type: year and month)
metric: record count
My time graph doesn't display anything. Can someone help me identify what's going on?
formatDate is the column created with the expression:
PARSE_DATETIME("%Y-%m-%d %H:%M:%S",REGEXP_EXTRACT( create_date,"(.*):[0-9]*"))
Using the date in its standard format, as mentioned at the beginning of the question, the same happens.
When entering dates (original and formatted), both appear with null values.
The milliseconds have to be separated by a . not a :. An option is to import your date a as string/text and add a calculated field, which parse the string in Data Studio:
PARSE_DATETIME("%Y-%m-%d %H:%M:%S",REGEXP_EXTRACT( data_field,"(.*):[0-9]*"))
If the dates are several years in the past, please adjust the Default date range in your graph:
I leave the solution to my problem to the community.
The problem is in the date format. Failed to get Google Data Studio to receive a date with milliseconds. By removing the milliseconds it was possible to work with the dates normally, managing to apply the available functions.
Note: It may be a knowledge limitation, but none of the date formatting functions work if the datetime field contains milliseconds (FORMAT_DATETIME, PARSE_DATETIME,...)

Subtract today's date from date field

In SSRS, I'm trying to build a calculated field that will calculate the number of days that have elapsed between a date field in my report and today.
I've tried =DateDiff("d",Fields!dts.Value,Today())

add days with date , different timezone not working

I want to add number of days with an existing date fetch from the database.When the timezone is (UTC+ 8:OO)Pacific Time US&CANADA momentjs addition working perfectly,But when i change timezone to (UTC+ 5:3O)Chennai,Kolkatta Momentjs addition not working,It returns the date that we given to add.
var inputtilldate =moment($scope.lasttilldate).add($scope.remdays-0, 'days');
This is the code for addition
Add format to the moment()
var inputtilldate =moment($scope.lasttilldate).add($scope.remdays-0, 'days').format();

Solr match any date in given month

In Solr, is it possible to search for all records in a given month regardless of the year or day ? For example, the snippet below would match everything on 01.01.2013 - what I want to do is find everything that appeared on 01.01 for any year.
date:2013-01-01T00:00:00Z
No, not with a date field. Solr can only deal with ranges of dates, just like it only deals with ranges of numbers or ranges of strings. Asking Solr to only query a date field based on the first day of the month is like asking it to query on a numeric field and only give you odd numbers, or querying a string but only those starting with vowels.
What you'll need to do is break up the date into month and day components and then query on those. If your base field is sale_date, you'll also need sale_month and sale_day. Then you can query on month:3 to get everything that happened in any March, or day:1 and get everything for the first day of any month or month:3 AND day:1 to get everything that happened on any March 1st.

How to compare two dates in Cakephp based on day, month, and year

I have a (hopefully) quick question. I have two dates stored in a database, ['Event]['start_time'] and ['Event']['end_time']. I want to compare the dates to see if they match based on day, month, and year, disregarding the hours, minutes, and seconds they were created. How do I pick out the details of my dates when they're in this format?
Are you trying to pull results where the start and end time match? You can do it like this:
$results = $this->Event->find('all',array('conditions' => 'DATE(Event.start_time) = DATE(Event.end_time)'));
DATE() is a MYSQL function that will just return the date in YYYY-MM-DD format and drop the time portion.
If you already have the data selected and want to compare it later, you can use the php functions date() and strtotime() like this:
if(date('Y-m-d',strtotime($start_date)) == date('Y-m-d',strtotime($end_date))) {
//dates are equal
}
where $start_date is ['Event']['start_time'] and $end_date is ['Event']['end_time']

Resources