Universe/U2/Pick ICONV() - universe

In U2/Universe/Pick, there is a function ICONV("11/11/15","D") to convert an external date to an internal date but this will work in USA or with the date format mm/dd/yyyy only. How can I use this function for UK date format (dd/mm/yyyy) ?

ICONV("11/12/15","D4/DMY")
output: 17512
According to the UniVerse BASIC Commands Reference documentation, you can also use the following to control the date format:
You can set the default date format with the DATE.FORMAT command. A
system-wide default date format can be set in the msg.text file of the
UV account directory. Date conversions specified in file dictionaries
or in the ICONV function or the OCONV function use the default date
format except where they specifically override it. When NLS locales
are enabled, the locale overrides any value set in the msg.text file.

NLS sets the local date format required so if it is enabled the following does not apply.
The question is, do you want all dates in dd/mm/yyyy format or just for this process. Assuming all dates should be, then setting DATE.FORMAT ON at login will do this. Otherwise you can set it temporarily just for the process and afterwards set it back using DATE.FORMAT OFF.

Related

Creating Timestamp in Google Workflow YAML

Trying to create a file output with date extension yyy-mm-dd etc. Cloud workflow does not have the date format functions of bigquery.
Closet I could get is ${time.format(sys.now())}, but that provides a timestamp.
Any way to parse to required format.
I suppose you mean a date extension in this format yyyy-mm-dd (your question says yyy-mm-dd).
${time.format(sys.now())} is giving me a timestamp like this:
2022-10-22T18:39:05.570539Z
With the text.substring() function ${text.substring(time.format(sys.now()), 0, 10)} I'm getting this string:
2022-10-22

Redshift uses wrong timezone when loading from S3

Redshift allows loading time-related types using its epoch representation as stated here by setting timeformat 'epochmillisecs' parameter of COPY command. It works great for TIMESTAMPs but something is broken for TIME columns.
Epoch value 1636984022000 (ms) that corresponds to 13:47:02.572000 is being imported as 22:41:11 by Redshift. I can see that it matches 13:47:02 UTC at PST (-08:00).
I tried alter user awsuser set timezone to 'UTC' and set timezone to default but it doesn't seem to help. What am I missing ?
Sometimes timezone issues can be hard to diagnose because SQL clients perform a conversion on the field when displaying data.
A trick I use is to convert the timestamp to TEXT so that the SQL client does not alter its contents. So, try selecting the data as SELECT field::TEXT to verify how it is actually being stored.
This prevents the SQL client from performing any nicely-intentioned timezone conversion and lets you see the 'real' underlying data.

Dataprep change str yyyymmdd date to datetime column

I have a column with dates (in a string format) in Dataprep: yyyymmdd. I would like it to become a datetime object. Which function/transformation should I apply to achieve this result automatically?
In this case, you actually don't need to apply a transformation at all—you can just change column type to Date/Time and select the appropriate format options.
Note: This is one of the least intuitive parts of Dataprep as you have to select an incorrect format (in this case yy-mm-dd) before you can drill-down to the correct format (yyyymmdd).
Here's a screenshot of the Date / Time type window to illustrate this:
While it's unintuitive, this will correctly treat the column as a date in future operations, including assigning the correct type in export operations (e.g. BigQuery).
Through the UI, this will generate the following Wrangle Script:
settype col: YourDateCol customType: 'Datetime','yy-mm-dd','yyyymmdd' type: custom
According to the documentation, this should also work (and is more succinct):
settype col: YourDateCol type: 'Datetime','yy-mm-dd','yyyymmdd'
Note that if you absolutely needed to do this in a function context, you could extract the date parts using SUBSTRING/LEFT/RIGHT and pass them to the DATE or DATETIME function to construct a datetime object. As you've probably already found, DATEFORMAT will return NULL if the source column isn't already of type Datetime.
(From a performance standpoint though, it would probably be far more efficient for a large dataset to either just change the the or create a new column with the correct type versus having to perform those extra operations on so many rows.)

C++ ParseDateTime() - SQL datetime as UK date

I have dates stored in datetime in an MSSQL database. In my C++ application, these dates are pulled out of the database and stored in a CString.
I am trying to use COleDateTime's ParseDateTime() to display these dates in a nice format. However I found they are being displayed in american format (MM/DD/YYYY), and sorted as such. I would like them displayed in UK format (MM/DD/YYYY). I have attempted the code below to no difference:
codt.ParseDateTime(sqlresults.GetItem(_T("date"),l),0,MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK));
Thanks!
The ParseDateTime function is used to read the provided value – in your case you get it from the database and set the internal representation of the COleDateTime object.
You are not after this method but rather after the COleDateTime::Format method.
codt.ParseDateTime(
sqlresults.GetItem(_T("date"),l),
0,
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
CString dateAsUkString = codt.Format(_T("%d/%m/%Y"));
// display the dateAsUkString string in your view

How to format date in SQLite according to current locale format settings?

I need to match on a date using the LIKE operator. The date should be in current user's local format, not in the general format.
So I use the strftime function like this:
WHERE strftime('%d.%m.%Y %H:%M', createdDate, 'localtime') LIKE '%{searchTerm}%'
Unfortunately this works only for fixed format '%d.%m.%Y %H:%M'. But I want to use the user's current locale format.
So I need to either:
1) Get the strftime format string from a C++ locale object
2) Make SQLite format the date using current locale itself
Spent already several hours on this to no avail.
Would be grateful if anyone would point me in the right direction on how to tackle this problem.
Example:
Given current locale is German I want to get something like "%d.%m.%Y %H:%m".
For an US locale I want to get "%m/%d/%Y %H:%m"
Normally the local date format can be obtained with the Windows GetDateFormat API (or GetDateFormatEx API for Vista). Your program could interrogate the API then transform the date accordingly. Following that, the date can be recorded in SQLite.
However, once can question the validity of storing timestamps in a specific format. That basically means a lot of code to manipulate each date, or no date manipulation at all. May I suggest, if it is possible, storing in a plain format (say ISO or UNIX timestamp) and working from that, outputing with whichever flavour of GetDateFormat is required?
OK, different answer.
Suppose you have your MyTable:
CREATE TABLE MyTable (
MyPrimaryKeyHnd INTEGER PRIMARY KEY,
...
CreatedDate TEXT);
(Where CreatedDate is in ISO format. I suppose you could also use a Unix timestamp. Your choice.)
Then a list of possible formats
CREATE TABLE TimeFormat (
TimeFormatHnd INTEGER PRIMARY KEY,
TimeFormatString TEXT NOT NULL,
TimeFormatDescriptor TEXT);
You allow your user to chose a format of their choice and keep that in a seperate table or INI file. TimeformatString would be your strftime() compatible format string (such as '%d.%m.%Y %H:%M'). You just need to build your query with whatever the user's choice is.