BCB6 How to display long date from DataSet Field in label? - date

I have a problem with displaying the correct date from a TDataSet.
In a TDataSet, I have a date in 'YYYY-MM-DD' format. On the computer, I have set the date in the d.mm.yy format, and so it has to stay, I can not change it.
Now, I have to take the date in the format 'YYYY-MM-DD' from the TDataSet and display it in a TLabel component in this format, but it always shows me the date in the 'YY-MM-DD' format, and that if the date is before 1969 then it adds 100 years.
I have my date in:
MyData->DataSet->Fields->FieldByName("date")
In my DB, my date is in YYYY-MM-YY format.
On my machine, I have the short date set to the 'DD-MM-YY' format, but I need to display my date in the label in 'YYYY-MM-DD' format.
I have no ideas for how to handle this.

TDateTime has a method named FormatString(). You can do this:
MyData->DataSet->Fields->FieldByName(L"date")->AsDateTime.FormatString("yyyy-mm-dd");

Related

Google App Script - how to set date with timezone in AdminReports.UserUsageReport.get()

I'm using Apps Script and trying to extract data from AdminReports.UserUsageReport.get('all', 'the date') (to get classroom last interaction timestamps), but it always comes with records from another day. For example, if I extract from the 5th, the report brings the 6th together, until 7 o'clock in the morning.
The date parameter is a string and in the documentation says the following:
Represents the date the usage occurred. The timestamp is in the ISO
8601 format, yyyy-mm-dd. We recommend you use your account's time zone
for this.
But if the parameter is a string in yyyy-mm-dd format, how am I going to pass the date with the right time zone?
This code not work:
var myDate = new Date(2021,5,5);
var timezone = Session.getScriptTimeZone();
var date = Utilities.formatDate(myDate, timezone, 'yyyy-MM-dd');
var page = AdminReports.UserUsageReport.get('all', date);
How do I use the date correctly?
Thanks a lot.
If the report dates are UTC, then each may first be converted to JavaScript Date objects using
var myDate = new Date('report_date_string');
The second two lines of your code look like they should follow correctly in converting and formatting the Dates to strings in your local time zone.

Date stored in different format

I have this date "2018-05-30T16:19:58.016Z" coming from my Angular app.
In Spring, the field date is as follows :
#JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
private Date date;
The date is well stored, but with this format YYYY-MM-dd.
Is there anything that I'm missing ?
MySql date type can't hold data with timestamp. It has to be datetime in order to contain date time with timestamp data.
You probably have to specify the date format going out to the storage, as #JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") only specifies the date format for parsing the date into the Date object. Even if your Date has all of the seconds and timezone information, the default Date toString() is still
Formats a date in the date escape format yyyy-mm-dd.
according to the Java 8 docs. So if you are using that, it would most likely drop all that extra information on conversion.
You can look at this Convert java.util.Date to String for information on how to get a Date to a formatted String.

How do I set Date AND time picker in MDriven?

I am trying to capture both date and time in MDriven, but the default for data type DateTime only shows a picker (in Web) for the date, but a time is stored in the persistency layer. How do I also capture the time?
I found this in the wiki.mdriven.net
Date-formatting You set date and time format in the Style attribute
enclosed in { }.
For example, for dates and time, {short} will show date and time in
compact format. The default date format is {shortDate}. Please refer
to the Angular guide for formatting dates
https://docs.angularjs.org/api/ng/filter/date
The date and time format are automatically localized depending on the
browser.

Changing date format without casting into text?

I need to change the date format from yyyy-mm-dd to dd/mm/yyyy, but I need to keep the date type for the column. So far, I have used this method that changes the format correctly but transforms the column type from date to text.
TO_CHAR(mydate::TIMESTAMP WITH TIME ZONE, 'dd/mm/yyyy'::TEXT) ;
How can I do it with keeping the date type?
This is a misunderstanding.
If your data type is date, then it is stored without format. It's just a 4-byte integer counting seconds since 2000.
You can format it any way when displaying to the client.
SELECT to_char(mydate, 'yyyy-mm-dd') AS one_way
,to_char(mydate, 'dd/mm/yyyy') AS other_way
'yyyy-mm-dd' happens to be ISO 8601 format, which is the default text representation in many locales.
You can always create a VIEW with a text representation of the date:
CREATE VIEW v_tbl_with_date_foramt AS
SELECT id, some_column, to_char(mydate, 'dd/mm/yyyy') AS mydate_text
FROM tbl;
But now it's a text column, not a date column.
datestyle is responsible for how input date literals are interpreted.
LC_TIME regulates how date/time functions behave.
Formatting Date(YY:MM:DD:Time) in Excel
The default display is the ISO 8601: 'yyyy-mm-dd'.

Date Column Split in Talend

So I have one big file (13 million rows) and date formatted as:
2009-04-08T01:57:47Z. Now I would like to split it into 2 columns now,
one with just date as dd-MM-yyyy and other with time only hh:MM.
How do I do it?
You can simply use tMap and parseDate/formatDate to do what you want. It is neither necessary nor recommended to implement your own date parsing logic with regexes.
First of all, parse the timestamp using the format yyyy-MM-dd'T'HH:mm:ss'Z'. Then you can use the parsed Date to output the formatted date and time information you want:
dd-MM-yyyy for the date
HH:mm for the time (Note: you mixed up the case in your question, MM stands for the month)
If you put that logic into a tMap:
you will get the following:
Input:
timestamp 2009-04-08T01:57:47Z
Output:
date 08-04-2009
time 01:57
NOTE
Note that when you parse the timestamp with the mentioned format string (yyyy-MM-dd'T'HH:mm:ss'Z'), the time zone information is not parsed (having 'Z' as a literal). Since many applications do not properly set the time zone information anyway but always use 'Z' instead, so this can be safely ignored in most cases.
If you need proper time zone handling and by any chance are able to use Java 7, you may use yyyy-MM-dd'T'HH:mm:ssXXX instead to parse your timestamp.
I'm guessing Talend is falling over on the T and Z part of your date time stamp but this is easily resolved.
As your date time stamp is in a regular pattern we can easily extract the date and time from it with a tExtractRegexFields component.
You'll want to use "^([0-9]{4}-[0-9]{2}-[0-9]{2})T([0-9]{2}:[0-9]{2}):[0-9]{2}Z" as your regex which will capture the date in yyyy-MM-dd format and the time as mm:HH (you'll want to replace the date time field with a date field and a time field in the schema).
Then to format your date to your required format you'll want to use a tMap and use TalendDate.formatDate("dd-MM-yyyy",TalendDate.parseDate("yyyy-MM-dd",row7.date)) to return a string in the dd-MM-yyyy format.