Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
Date formatting MongoDB, Want to remove timezone

I want to get the blog post date, however, when I use the following, I get the following format: Fri Jan 21 2022 20:09:28 GMT+0000 (Greenwich Mean Time).

I only want, Fri Jan 21 2022

How can I do this?

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const blogSchema = new Schema({  
 
  date: { 
    type: String,
    default: date
   }

}, { 
  timestamps: true
});

I'm then just sticking that date into my EJS file as follows

<p class="date"><%= blog.date %></p>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming you want an easy answer, you could just do something like this:

<p class="date"><%= blog.date.match(/^[a-z]{3}\s[a-z]{3}\s\d{2}\s\d{4}/i)[0] %></p>

or, even simpler:

<p class="date"><%= blog.date.slice(0,15) %></p>

These both assume that your date is already a string (I don't use mongo). If it's not, a toString() after blog.date should suffice to make them work.

You could also use something like the (excellent) moment.js library for this, but that might be overkill for your use case.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!