System Date & Time Format

Have tried to see if overide regional setting effects but doesnt seem to.
Is there a way we can set a date/time format overide?
Always have such nightmares handeling dates in scripts and changing windows date format is a pain if using allot of excel docs etc as yyy-MM-dd is not the natural format for most when typing dates.

1 Like

I have had horrible nightmares with this…

the best solution I could find (and its not SAMBA related problem, but windows and beeing so egocentric) is to NOT override regional settings…

and in all reports try to use samba embedded {START DATE} tag.

If you need date in sql or scripts the best way is to use them as you regional settings are setted. This will confuse you at the begining since you will have to use two set of date settings… at least that happend to me in brazilian setting with money and dates…

Hope this helps

G

I have the solution but just woundered if there was an easier way.
var endDate = new Date(calculatedEndDate); //–define date of calculated end

    var endDateValue                                                = endDate.valueOf();                                                                                    //--numerical value of calculated end

    var endDateYear                                                    = endDate.getYear();                                                                            //--End date breakdown

    var endDateMonth                                                = endDate.getMonth()+1;                                                                                    //--get date month

    var endDateDay                                                    = endDate.getDate();                                                                                     //--get date day

    var endDateHours                                                = endDate.getHours();                                                                                    //--get date hour

    var endDateMinutes                                                = endDate.getMinutes();                                                                                    //--get date minutes

    var endDateSeconds                                                = endDate.getSeconds();                                                                                    //--get date seconds

    var endDateFormatted                                            = endDateYear+'-'+endDateMonth+'-'+endDateDay+' ';                                                //--End date formatting for sql

    endDateFormatted                                                += endDateHours+':'+endDateMinutes+':'+endDateSeconds;

that is way too complicated…
in my humbile experience with three setups… I could with help, obviously, always replace those complicated functions with something really simple…

where are you suing those?

G

Several times for posting to API which requires SQL date format yyyy-MM-dd hh:mm:ss

Its not that complex, just gets the values and formats them as needed in a string.
Found this to be most reliable method but it does look so clumbersome.

Most anoying part is that that isthe format they are in in Samba database LOL

The revised script will use this as a function rather than duplicated but just could not get any date formatting functions to do what that does.

1 Like

Set Windows to that ^ because any other way is wrong.

Do not override Regional Settings in SambaPOS. There is no need to do that when you set Windows to the proper format.

All of the SQL I write for SambaPOS has this:

-- PARM for Date Filter Start
declare @StartDateIn varchar(25) = '@3'
-- PARM for Date Filter End
declare @EndDateIn varchar(25)   = '@4'

-- set START and END date for Report Period
declare @StartDate datetime = convert(varchar(25),@StartDateIn,126)
declare @EndDate datetime = convert(varchar(25),@EndDateIn,126)

The important part is that you take in the Date/Time as a varchar (ie. @StartDateIn), then convert it to datetime (ie. @StartDate) for actual use through the rest of the script. The CONVERT(..., 126) puts the var into the proper ISO format, no matter what weird garbage format you fed into it. Then you don’t worry about it.

The same goes for JScript …

1 Like

That went over my head but will have a play.
(Just fyi end date wasnt anything to do with report date, it was a calculated date to work out the end of the ticket close date/time batch run on hourly script.)