# K6 date manipulation libraries ala dayjs

**URL:** <https://community.grafana.com/t/k6-date-manipulation-libraries-ala-dayjs/159553>\
**Category:** OSS Support\
**Created:** [November 20, 2025, 8:30am UTC](https://community.grafana.com/t/k6-date-manipulation-libraries-ala-dayjs/159553 "2025-11-20T08:30:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fenchu](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/fenchu/32/44330_2.png) [@fenchu](https://community.grafana.com/u/fenchu)\
**Post date:** [November 20, 2025, 8:30am UTC](https://community.grafana.com/t/k6-date-manipulation-libraries-ala-dayjs/159553/1 "2025-11-20T08:30:42Z")

</div>

I’ve always had a small pure js library for manipulating dates, but now I work on another project where this is taken to another level. So instead of investing in my own library, can I use libraries like npms [dayjs - npm](https://www.npmjs.com/package/dayjs)

---

<div class="post-metadata">

**Author:** ![fenchu](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/fenchu/32/44330_2.png) [@fenchu](https://community.grafana.com/u/fenchu)\
**Post date:** [November 21, 2025, 1:18pm UTC](https://community.grafana.com/t/k6-date-manipulation-libraries-ala-dayjs/159553/2 "2025-11-21T13:18:20Z")

</div>

Luckily dayjs has a minimized browser js, so it can be directly imported, I also included the utc extension. There is another extension I like to add [dayjs-timezone-iana-plugin - npm](https://www.npmjs.com/package/dayjs-timezone-iana-plugin), but it holds a iana database, I’ll probably just make the extraction what I need and pack it together:

> $ cat test-dayjs.js  
> // [https://cdn.jsdelivr.net/npm/dayjs@1.11.19/dayjs.min.js](https://cdn.jsdelivr.net/npm/dayjs@1.11.19/dayjs.min.js)  
> import dayjs from ‘./tools/dayjs.min.js’;  
> // [https://unpkg.com/dayjs-plugin-utc@0.1.2/dist/dayjs-plugin-utc.min.js](https://unpkg.com/dayjs-plugin-utc@0.1.2/dist/dayjs-plugin-utc.min.js)  
> import utc from ‘./tools/dayjs-plugin-utc.min.js’;  
> // inject utc plugin to dayjs  
> dayjs.extend(utc);
> 
> export default function () {  
> const now = dayjs();  
> console.log(‘Current time:’, now.format(‘YYYY-MM-DD HH:mm:ss’));  
> const dt = dayjs().startOf(‘month’).add(1, ‘day’).set(‘year’, 2018).format(‘YYYY-MM-DD HH:mm:ss’);  
> console.log(‘specific time:’, dt);  
> const utct = dayjs(‘2022-11-30T21:00:00.00+01:00’).utc();  
> console.log(‘norwegian to utc time:’, utct);  
> const dayA = dayjs();  
> const dayB = dayA.clone().add(1, ‘day’);  
> const dayC = dayA.clone().subtract(1, ‘day’);  
> const dayD = dayA.clone().add(1, ‘month’);  
> console.log(dayC.isBefore(dayA)); // true  
> console.log(dayA.isSame(dayjs())); // false microsecdiff  
> console.log(dayB.isAfter(dayA)); // true  
> console.log(dayA.isSame(dayD)); // false  
> console.log(dayB.isAfter(dayD)); // false  
> console.log(dayC.isBefore(dayD)); // true  
> // generate one month of dates from today  
> let days =   
> for (let d=dayA.clone(); d\<=dayD; d=d.add(1, ‘day’)) {  
> days.push(d.format(‘YYYY-MM-DD’));  
> }  
> console.log(days);  
> }

> $ k6 -q run test-dayjs.js  
> INFO[0000] Current time: 2025-11-21 14:17:05 source=console  
> INFO[0000] specific time: 2018-11-02 00:00:00 source=console  
> INFO[0000] norwegian to utc time: “2022-11-30T20:00:00.000Z” source=console  
> INFO[0000] true source=console  
> INFO[0000] false source=console  
> INFO[0000] true source=console  
> INFO[0000] false source=console  
> INFO[0000] false source=console  
> INFO[0000] true source=console  
> INFO[0000] [“2025-11-21”,“2025-11-22”,“2025-11-23”,“2025-11-24”,“2025-11-25”,“2025-11-26”,“2025-11-27”,“2025-11-28”,“2025-11-29”,“2025-11-30”,“2025-12-01”,“2025-12-02”,“2025-12-03”,“2025-12-04”,“2025-12-05”,“2025-12-06”,“2025-12-07”,“2025-12-08”,“2025-12-09”,“2025-12-10”,“2025-12-11”,“2025-12-12”,“2025-12-13”,“2025-12-14”,“2025-12-15”,“2025-12-16”,“2025-12-17”,“2025-12-18”,“2025-12-19”,“2025-12-20”,“2025-12-21”] source=console
> 
> █ TOTAL RESULTS
> 
> ```auto
> EXECUTION
> iteration_duration...: avg=14.55ms min=14.55ms med=14.55ms max=14.55ms p(90)=14.55ms p(95)=14.55ms
> iterations...........: 1 68.24957/s
> 
> NETWORK
> data_received........: 0 B 0 B/s
> data_sent............: 0 B 0 B/s
> 
> ```
