Help with Day() and Month() functions


#1

Hi there,

I have a problem with the day() and month() functions. I have this date:

10/08/2018

#Day('10/08/2018')# returns 08

similarly,

#Month('10/08/2018')# returns 10

The above suggests that my locale has a date of the form of ‘mm/dd/yyyy’

I try to confirm this, so I do a #getLocale()# and this returns 'english (uk)'

but truth is that English (UK) , is using a dd/mm/yyyy

So, how can i fix this? I want Month() to return 08 and Day() to return 10.

Any help would be much appreciated!

Thank you,
George


#2

The accepted answer on this should help.


#3

Thanks a lot for the suggestion! Yes, converting string-to-date-object , using LSDateFormat() though, works fine. It’s just like a hacky way though which does the thing.

Basically, I have a string, of ‘10/08/2018’. If I do an LSDateFormat(‘10/08/2018’,‘dd’) I can get the correct day (=10).

If I do a day() this will return an 8.

So, all dates should go through LSDateFormat.

It would be good if lucee had a global setting to set the locale of all date functions, such as month(), day(), DateAdd(), DateDiff(), etc.

but your recommendation simply works, thank you!
George


#4

there is LsWeek and LSDayOfWeek, but no LsDay or LsMonth

the non LS functions should always be the same regardless of local

I’d like to see a LSParseDate function
https://luceeserver.atlassian.net/browse/LDEV-1552


#5

The regular date function are all EN_US locale based, so this function do not care about the current locale set in the environment. So best always use the “ls” function instead if they are existing or make sure you are passing a date object (convert it before) and not passing a string.
I have somewhere a spreadsheet that shows which function “ls” matching the regular date function, i will search for it.
We should consider filling the gaps of the missing ls functions, in that case at least “lsDatePart”.


#7

i did digg a little bit deeper into this.
“ls” function that convert a date to a string like regular date function as well.are expecting a date as input.
So your string gets converted to a date BEFORE it is passed into for example the “Day” function.
So “lsDay” would make no difference on this. So if you have a string and want it converted to a date, do it explicitly otherwise it is always US locale based. So use paseDateTime for example instead.
We should consider a global setting and application.cfc setting influence this behaviour.


#8

IMO there should be a setting that allows you to specify the state locale as the default locale instead of the en-US locale.