Re: How to convert date to string?
Posted by: James Leo
Date: March 19, 2021 02:54AM

Hello everyone,
I got a bit of the DATE value by chance.
If you read the DATE in 'byte' way, it will return 4 bytes, for example:
e5, 0f, 01, 1a --> (year 2021), mon 1, day 26
2021(dec) -> 07 e5 (hex), so you can get the real DATE as :

mysqlx_get_bytes(row, 3, 0, sdate, &buf_len); //col 3 == DATE, sdate -> char []
if (buf_len == 4) {
unsigned int nYear =(unsigned int) (sdate[1] & 0x07) << 8;
nYear +=(unsigned char) sdate[0];
s.Format("%04d-%02d-%02d",nYear , sdate[2],sdate[3] );
}

I'm not sure what does 0x08 means ( less than 2000 year?), just change 0x0f to 0x07.

Or it is just a coincidence?

Best Regards

James

Options: ReplyQuote


Subject
Views
Written By
Posted
794
March 16, 2021 03:22AM
458
March 16, 2021 08:49PM
Re: How to convert date to string?
372
March 19, 2021 02:54AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.