Regional setting confusion regarding date format from PostgreSQL - delphi

I'm working on an application that requires the following regional settings (Delphi 7 and PostgreSQL 9.0):
1. DateSeparator:='/';
2. TimeSeparator:=':';
3. ThousandSeparator:=',';
4. DecimalSeparator:='.';
5. ShortDateFormat:='MM/dd/yy';
6. ShortTimeFormat:='hh:mm:ss';
I need to change the regional setting only for my application and not system wide.
In OnCreate of the form I set the above separators, and
my current system separators are:
1. DateSeparator='|';
2. TimeSeparator='|';
3. ThousandSeparator='|';
4. DecimalSeparator='|';
(This is for the test purpose.)
Now in Postgres I have a table from where I get dates to display in my application but somehow the dateseparator doesn't seem to work (as seen in label1)!
Check the image.
I fire a query to get the dates from the table
Label1.Caption:=(Fields(1).Text);
Label2.Caption:=datetostr(Fields(1).Data) ;
The query is
select min(dat), max(dat) from diary where survey in (2008401) and event not in ('E','C','R') and region=6100;
now the same date if I take as .data differ in the date separator from .text dateseparator
why this is happening?
Why are the regional settings not applied to label1.caption (as shown in the image)?

DateToStr uses ShortDateFormat as the output format. You didn't change that from the MM/dd/yy set initially; you only changed the DateSeparator.
I'm confused though, about why you'd want to use (Fields(1).Text) (is that right? Parentheses instead of [] for the Fields subscript?).
If the DB is configured to use | as the date separator, as it appears it is from your screen image, why are you using DateToStr? It appears that .Text is getting the information in the format you're looking to obtain.

ok i found on one site
enter link description here
for getting the appropriate format all i had to do was get the fire the query as
select to_char(min(dat),'mm/dd/yy'), to_char(min(dat),'mm/dd/yy')
from diary
where survey in (2008401) and
event not in ('E','C','R') and region=6100;
This gave me the proper result in the format i wanted

Related

Changing timezone for a default timestamp column in Snowflake

I have a table defined in snowflake as follows;
CREATE OR REPLACE TABLE DATA_LAKE.CUSTOMER.ACT_PREDICTED_PROBABILITIES(
PREDICTED_PROBABILITY FLOAT,
TIME_PREDICTED TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
As expected default timezone is America/Los Angeles. I am trying to change it to UTC, but only for this column, not at account/session level.Here is the code I wrote;
ALTER TABLE DATA_LAKE.CUSTOMER.ACT_PREDICTED_PROBABILITIES ALTER TIME_PREDICTED SET timezone= 'UTC';
But it is giving an error,
SQL compilation error: syntax error line 1 at position 86 unexpected 'timezone'.
Can I please get help on how to do the change at column level?thanks in advance.
I recommend reviewing this documentation regarding timestamp data types:
https://docs.snowflake.com/en/sql-reference/data-types-datetime.html#timestamp
However, assuming that your TIMESTAMP_TYPE_MAPPING is still the default of TIMESTAMP_NTZ, then you've now got a bunch of data that is set to America/Los Angeles without a timezone offset in the values, and if you're not going to change any of your account timezone settings, then you either need to leave it that way and just change the timezone as you select the data using the CONVERT_TIMEZONE function, or you should change your table definition to a data type that includes a timezone offset. You could also update the column as it is by converting it with the same CONVERT_TIMEZONE function, but then future data would still be inserted using America/Los Angeles timezone.
My recommendation is to use TIMESTAMP_TZ as your column type and modify the current data accordingly.

My Time Field in my DBGrid is showing the date and time instead of time only - delphi

I have a field in my database called 'Times', it's a date/time format and its format is set to 'short time'. In my database the date does not show, nor is it being add to the database as I know. It is only the time value. My DBGrid shows the time field with the time value and the date '12/30/1899'. How do I get rid of the date in my time field.
Here is the code I used to submit to the database.
Get time value:
bookingtimes:= timeof(dttime.Time);
Submit to Database:
tblbooking.FieldByName('Times').AsDateTime:=bookingtimes;
Example of DBGrid 'Times' column output:
12/30/1899 7:02:01AM
If I understand what you mean this will work for you, just follow this steps:
This is your issue:
Double click on your table, and select Times field:
After you click on your field, go to the Object Inspector and find DisplayFormat property:
Write the format, in your case hh:mm:ss:
Now let's see the result:
That's it.

Rails - regex to find specific date

In app I build to learn rails, I am working on finding data. Now I have this case: in this text, I want to find the right delivery date.
"delivery date 01/12/2015 delivery note 30112016 invoice date 03.01.2016"
The regex I made get all the dates:
[0-9]{1,2}[-.\/][0-9]{1,2}[-.\/][0-9]{2,4}
How to add the condition that it picks the date preceded "delivery date"?
Add delivery date to the pattern and capture the date:
s[/delivery date\s*(\d{1,2}[-.\/]\d{1,2}[-.\/]\d{2,4})/, 1]
See the online Ruby demo
The 1 argument tells Ruby to only fetch the contents captured within the first capturing group now.
Just in case you are interested in dates that have consistent separators, you may consider using
/delivery date\s*(\d{1,2}([-.\/])\d{1,2}\2\d{2,4})/
^^^^^^^^ ^^
where the separator is captured into Group 2 and the value is re-used later with the backreference \2.

TABLEAU: calc field to get the last value available

I'm using Tableau Desktop, my data are like this:
KPI,date,monthValue
coffee break,01/06/2015,10.50
coffee break,01/07/2015,8.30
and I want to build a table like this
KPI, year(date), last value
coffee time, 2015, 8.30
How can I set a calculated field in order to show me the last value available in that year? I tried to do:
LOOKUP([MonthValue], LAST())
But it didn't work and tells me 'cannot mix aggregate and non-aggregate', so I did:
LOOKUP(sum([MonthValue]), LAST())
But it didn't work too. How should I proceed?
If you are using Tableau 9 then you can do this with an LOD calc that looks for the max value in your date field and then checks if the current date value is the same as the max date value.
[Date] == {fixed: max([Date])}
As you can see in the example below when you use the calc as a filter you will only get the last row from your example above.
UPDATE: to get the values per year you can do something like:
Here I am using a table calculation to find the max date per year and then ranking those dates and filtering down to the latest date in each year (which will be the one that has a rank equal to 1).
!max date is WINDOW_MAX(ATTR(Date))
!rank is RANK(Date)
You need to make sure that the table calculations are computer in the correct way (in this case across the values of each year).

I'm getting "Invalid month in date" trying to run this?

I'm trying to run the following db command against Informix:
delete from table1
where u_id in (select u_id
from table2
where c_id in (select c_id
from ptable
where name = 'Smith'
and dob = '29-08-1946'));
I pass this in as a string to the db.ExecuteNonQuery method in the MS Data Application block and I get the above error?
To get the date format '29-08-1946' to work, you need your DBDATE environment variable set to a value such as "DMY4-" (or "DMY4/"). These are standard variations for the UK (I used them for years; I now use "Y4MD-" exclusively, which matches both ISO 8601:2004 (Date formats) and ISO 9075 (SQL), except when debugging someone else's environment). There are other environment variables that can affect date formatting - quite a lot of them, in fact - but DBDATE takes priority over the others, so it is the big sledgehammer that fixes the problem.
One of the problems is that your notation using a plain string is not portable between US and UK (and ISO) settings of DBDATE. If you have a choice, the neutral constructor for dates is the MDY() function:
WHERE dob = MDY(8,29,1946)
This works regardless of the setting of DBDATE. You can probably use TO_DATE() too:
SELECT TO_DATE('29-08-1946', '%d-%m-%Y') FROM dual;
This generated '1946-08-29 00:00:00.00000' for me - the function generates a DATETIME YEAR TO FRACTION(5) value, but those convert reliably to DATE values in Informix.
You can also use the DATE() function or an explicit cast to DATE (either CAST('29-08-1946' AS DATE) or '29-08-1946'::DATE), but both of those are subject to the whims of the locale of the users.
Your date field is improperly formatted. Since there is no 29th month in the year 1946 that is what is causing the error.
I'd try just swapping the month and day. 08-29-1946.
The way the day and month parts of a date string are read in can depend on your computer's culture settings.
It is always safer to pass date strings to a database in the form 'dd-MMM-yyyy' (i.e. '29-aug-1946')
It's even safer to pass them as YYYY-MM-DD, the dd-MMM-yyyy in that example will fail on a server with a (for example) French locale.

Resources