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