Monday, 29 May 2017

How to format date using html in nodemailer

I'm trying to send an email using nodemailer. But I'm having difficulties to convert date and time format. The codes below are in my routes/index.js(backend). This is a confirmation message that will send to customer thru email.

var data = req.body;

var mailOptions = {
  from: 'Caretel <caretelservice@gmail.com>', //'Caretel <caretelservice@gmail.com>',
  to: data.customer_email, //data.customer_email,
  subject: 'Booking has been confirmed.',
  html: '<b>' + data.company_name + '</b><p> has accepted your request. Here are the requested details: </p><ul><li><b>Car: </b>' + data.car_type + '</li><li><b>Date: </b>' + data.booking_date + '</li><li><b>Time: </b>' + data.booking_time + '</li><li><b>Price: </b>RM' + data.total_price + '</li></ul><p>For further information please contact <b>0' + data.company_number + '</b>.</p><br><br><h2>Thank you</h2><h4>for using</h4><h3>Caretel =)</h3>'
};

I want data.booking_date and data.booking_time to display only in the format of date(m/d/y) and time(H:m am/pm) respectively. Using the codes above will give the full stirng of data.booking_date and data.booking_time. I have tried to use JavaScript like this

var n = data.booking_date;
var y = n.getFullYear();
var m = n.getMonth() + 1;
var d = n.getDate();

but it didn't work. Anyone has any ideas how to convert this?



via Azinuddin AleleCha

No comments:

Post a Comment