I need to include in a query a date time value.
Need it works on any datetime format, in windows and linux.
Sample
where adate = ''+ dateformated+''
Some regional meetings have mm/dd/yy and another have dd/mm/yy
Theres any way to know which is the expect date format string for postgres server? some way to interrogate the server?
Or any other suggestion?
Bets regards
Safe way to pass a date time value to string in a query
-
- Posts: 13
- Joined: Thu 16 Aug 2018 15:54
Re: Safe way to pass a date time value to string in a query
Hello,
It is not known your database and version.
There is an SQL standard for date time values.
yyyy-mm-dd hh:mm:ss
It supposed to work in all cases if you format your datetime always like above. That is valid for FirebirdSQL, PostgreSQL, MySQL, SQL Server at least.
SQLite it works if you also insert your records like in above format as SQLite does not have any specific datetime data type.
It is not known your database and version.
There is an SQL standard for date time values.
yyyy-mm-dd hh:mm:ss
It supposed to work in all cases if you format your datetime always like above. That is valid for FirebirdSQL, PostgreSQL, MySQL, SQL Server at least.
SQLite it works if you also insert your records like in above format as SQLite does not have any specific datetime data type.
-
- Posts: 13
- Joined: Thu 16 Aug 2018 15:54
Re: Safe way to pass a date time value to string in a query
Thanks will try.
Do you mean
'yyyy-mm-dd hh:nn:ss'
rigth?
Do you mean
'yyyy-mm-dd hh:nn:ss'
rigth?
Re: Safe way to pass a date time value to string in a query
I meant to format your date/date time like that and pass as if it is a string parameter (with single quotes)
Today is 25th of March, 2020 15:29
That should be formatted as
2020-03-25 15:29:00
And passed as a string parameter to query.
That format normally accepted by common sql servers. Almost all of them
Today is 25th of March, 2020 15:29
That should be formatted as
2020-03-25 15:29:00
And passed as a string parameter to query.
That format normally accepted by common sql servers. Almost all of them
-
- Posts: 13
- Joined: Thu 16 Aug 2018 15:54
Re: Safe way to pass a date time value to string in a query
Exactly, but the format to convert is that
'yyyy-mm-dd hh:nn:ss'
and not that you write
yyyy-mm-dd hh:mm:ss
for that reason I pointed out to serve other read it in a future.
Thanks
best regards.
'yyyy-mm-dd hh:nn:ss'
and not that you write
yyyy-mm-dd hh:mm:ss
for that reason I pointed out to serve other read it in a future.
Thanks
best regards.
Re: Safe way to pass a date time value to string in a query
Ertrank is right. When passing the date-time parameter as a string, database server settings will be applied rather than the local system settings. The 'yyyy-mm-dd hh:nn:ss' format is supported in many database servers.