---
title: "Create a string code based on current date and time which includes \"0\" digits, e.g. \"0812\" for 8h12"
url: "https://openforis.support/questions/2841/create-a-string-code-based-on-current-date-and-time-which-includes-0-digits-eg-0812-for-8h12"
tags: ["collect"]
status: "answered"
score: 0
answer_count: 2
asked: "2020-06-04T07:23:09"
last_activity: "2020-06-05T10:49:29"
source: "Open Foris Support - Q&A Forum"
license: "Copyright Open Foris, 2026. Some rights reserved under creative commons license."
---

# Create a string code based on current date and time which includes "0" digits, e.g. "0812" for 8h12

Asked by bsenterre on 2020-06-04

Dear Open Foris team,
I have a survey where I create a unique code based on the concatenation of the date and time.
date_indiv: default value = idm:currentDate()
time_indiv: default value = idm:currentTime()
code: default value = concat(date_indiv,"-",time_indiv)

How can I modify my expression to obtain a code which includes "0", for example "0912" for 9h12: thus "20200604-0912". My current expression gives me "20200604-912"; so it seems to do it automatically for the date but not for the time.

Thanks a lot in advance,
Bruno


## Answer (score 0, by lcomas on 2020-06-04)

Link: https://openforis.support/questions/2841/create-a-string-code-based-on-current-date-and-time-which-includes-0-digits-eg-0812-for-8h12/2842

Hello, 

For the same question I used the nexts expressions in the default value: 

concat(substring(date,3,6),"_",time) apply when time>=1000;

concat(substring(date,3,6), "_0",time) apply when time>=100;

concat(substring(date,3,6), "_00",time) apply when time>=10;

where date is a field with default expression idm:currentDate() and time with idm:currentTime() 

Lluís


## Answer (score 0, by bsenterre on 2020-06-05)

Link: https://openforis.support/questions/2841/create-a-string-code-based-on-current-date-and-time-which-includes-0-digits-eg-0812-for-8h12/2843

Thanks a lot for your speedy reply. It worked.
Best wishes,
Bruno
