Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

262
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda