0

I'm trying to do excel export using alasql and passing my date,12 Apr 2018 by transforming using below function

    var dateStr = "12 Apr 2018";
    function trandformDate(dateString){ 
        var date = new Date(dateString);
        return new Date(date.setDate(date.getDate() + 1));
    }
    var date = trandformDate(dateStr); 

When the excel gets generated I was able to see the date in MM/DD/YYYY format with the timezone.I would like to keep the date and removw timezone from excel.Please let me know how can I send time without timezone to excel so that the format remains the same ie., MM/DD/YYYY enter image description here

forgottofly
  • 2,729
  • 11
  • 51
  • 93
  • ..."with timezone"? Do you mean "with the time"? – ashleedawg May 25 '18 at 06:36
  • @ashleedawg I mean "with the time" – forgottofly May 25 '18 at 06:40
  • To confirm: you know how to get a datetime into Excel: `4/12/2018 6:30:00 PM` but you want to remove the time (so you have `4/12/2018`), and you want to do that in JavaScript, so this is *not* an Excel question, correct? – ashleedawg May 25 '18 at 06:47
  • Possible duplicate of [How do I remove time part from JavaScript date?](https://stackoverflow.com/questions/34722862/how-do-i-remove-time-part-from-javascript-date) – ashleedawg May 25 '18 at 06:50
  • 1
    Don't put changes in comments, edit the question. It's very unclear. – RobG May 25 '18 at 12:31

2 Answers2

2

Fixed by passing the date and setting timestamp to 0 using setUTC()

var dateStr = "12 Apr 2018";
transformDate(dateString) {
        const date = new Date(dateString);
        const timeStamp = new Date(date.setDate(date.getDate() + 1));
        timeStamp.setUTCHours(0);
        timeStamp.setUTCMinutes(0);
        timeStamp.setMilliseconds(0);
        return timeStamp;
    }
var date = trandformDate(dateStr);
forgottofly
  • 2,729
  • 11
  • 51
  • 93
0

Simply split the array by space, and then use only the first part of the array.

var date = new Date();
date = date.split(" ")[0];
Benjamhw
  • 97
  • 8