Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
How to get start and end timestamps of every month in selected year

so i have timestamp for the begining of the year (Friday, 1 January 2021 00:00:00) and end of the year( Friday, 31 December 2021 23:59:59 )

{ yearStart: 1609455600000, yearEnd: 1640991599000 }

because i need to get data for every month in this year i need start and end timestamps of a month. is there any method for this? ty in advance

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I suggest to use a date and time module. For example dayjs

There are helpers like startOf('month') or add() .

Here is some pseudo code of the module regarding your problem. I suggest you to learn it as date and time is handy to now in lots of projects.

const dayjs = require('dayjs')

// Initialise dayjs object with your provided start of year timestamp.
const startOfYear = dayjs(1609455600000)

// set to start end endof month
const january_start = startOfYear.startOf('month')
const january_end = startOfYear.endOf('month')

// add one month and set to start resp. end of
const february_start = startOfYear.add(1, 'month').startOf('month')
const february_end = startOfYear.add(1, 'month').endOf('month')

// ... loop and go further..


// Helper function for getting back javascript dates.
const numeric_date = startOfYear.toDate().getTime()

// there is also a format() function which allows printing
// nice looking dates.

startOfYear.format('MMM DD YYYY') // => prints 01 Jan 2021

For more info read the docs

about 4 years ago · Juan Pablo Isaza Relatório

0

Use the following code to create a stored procedure or table-valued function. Format the output as desired.

declare @year varchar(4)
set @year = '2022'

; with cte as
 (select 0 'n' union select 1 union select 2 union select 3 union select 4 union select 5 union select 6
  union select 7 union select 8 union select 9 union select 10 union select 11)

select   dateadd(month, n, '1/1/'+@Year) 'yearStart'
, dateadd(second, -1, dateadd(month, n +1, '1/1/'+@Year)) 'yearEnd'
 from cte

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda