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

5
  • ..."with timezone"? Do you mean "with the time"? Commented May 25, 2018 at 6:36
  • @ashleedawg I mean "with the time" Commented May 25, 2018 at 6: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? Commented May 25, 2018 at 6:47
  • Possible duplicate of How do I remove time part from JavaScript date? Commented May 25, 2018 at 6:50
  • 1
    Don't put changes in comments, edit the question. It's very unclear. Commented May 25, 2018 at 12:31

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

Comments

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];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.