biggner needs help in dates

const d = new Date ()
const currentdate = d . toLocaleDateString ()

export function button2_click ( event ) {
let toInsert = {
“title” : ‘’ ,
“detail” : $w ( ‘#textBox1’ ). value ,
“date” : currentdate
};

wixData . insert ( "visits" ,  toInsert ) 
    . then (( results ) => { 
        **let**  item  =  results ;  //see item below 
    }) 
    . **catch** (( err ) => { 
        **let**  errorMsg  =  err ; 
    }); 
$w ( '#textBox1' ). value  =  '' 

}

i have a stupid problem i can’t fix it
all what this code do store the damn local date

but when i check how the stored date looks like i finde this


i wnat it to be like this : 24 / 2 / 2022
please help i am stressed out for 2 ours

Hello. What field type are you using in the collection? If it is a date field, then my guess is that toLocaleString is what is messing you up because when you use that, the date is no longer a date object but a string.

also I am moving this post to coding with velo, it be more appropriate in that category

first of all thank you for your concern

and take a look at this

i know it is a string the field type is text
still do not understand where is the problem

I just tested on my site with your code and the string was inserted as expected so this is curious. I noticed that in your screenshot it says that this site has not been published yet. Are you able to publish and test not in preview just to rule out a preview mode oddity?

Hi @yaser1999yaser & @amandam
I think the problem lies with the settings of your computer.
If i do it i get the following 24-02-2022

I think its some problem with your timezone.

Try this

const currentdate = d . toLocaleDateString ( ‘en-US’ )

@volkaertskristof Yes! That was my next guess as well. I believe you nailed it. Thanks for weighing in

@amandam
no Problem,
Happy to help where i can :blush:

@amandam & @volkaertskristof
const currentdate = d . toLocaleDateString ( ‘en-US’ )
this line solve it thanks for both of you guys

but when amanda said try the published version , there it is another problem.

the code now is running smoothly , but only in preview mode and dose not work in the published site
(what i meant by dose not work that when i go to the collection there is no data have been inserted)

can any one tell why ?

Check your collection permissions for read/write and see if that solves the issue

@amandam thank you much
i forgot all about permissions
every thing is amazing right now thank you so much for your time amanda
i really mean it thank you

but i have one last question the format of this date ( 2/24/2022 ) is “mm/dd/yyyy”

but i want it to be “dd/mm/yyyy”

can i do that ?
i did my search online but i jus got lost

and i am sorry i had to put into all that trouble

@yaser1999yaser No worries at all! It’s always these little things that trip us up.

As for the order, since you are currently using en-US it is formatting for US. I believe en-GB will swap the format for you. If I am wrong, check the options for what you can pass to it in the MDN docs.

@amandam
I USED THE en-GB AND IT WORKS

THANKS SO MUCH