Reactjs - latest Date selection -
am displaying array of dates. have pick latest date out of date array. please suggest how can latest date.
class searchresultsitem extends react.component { render() { return ( <tr onclick={ this.handleopen } style={{fontsize: '10',cursor: 'pointer'}}> <td>{ this.props.item.number }</td> <td>{ this.props.item.name }</td> <td>{ this.props.item.buyer_name }</td> <td>{ this.props.item.order_date ? <moment format="dd-mmm-yyyy">{ this.props.item.order_date }</moment> : null }</td> </tr> <div classname="col-sm-3"> <input name="date" disabled={ this.state.mode } type="date" value={ this.state.item.date } classname="form-control" onchange={ this.handleinputchange } /> </div> ); }
here solution might want try, converts given array of strings date object , compare.
var dates = ["2009-09-09", "2017-16-07", "2001-29-01"]; var latest = dates[0]; for(var = 1; < dates.length; i++) { if (formattodate(dates[i]) > formattodate(latest)) latest = dates[i]; } alert(latest); function formattodate(datestring) { var d = new date(); datestring = datestring.split('-'); d.setfullyear(datestring[0]); d.setmonth(datestring[1]); d.setdate(datestring[2]); return d; }
orignal answer here
Comments
Post a Comment