What timestamp format is "xTxx:xx:xx"? - date

I have come across a certain attribute that returns timestamp values in a format like - "xTxx:xx:xx". What does the first 'x' signify?
My first guess was that the first 'x' stands for days but I'm not sure if that's right or not.

Related

Why does RANDARRAY in Excel's "integer" parameter include dates that are outside of the directed min/max values?

In Excel, I am trying to create random dates based on three cell values:
Start Date
End Date
Size
Random Dates
2/1/2022
1/31/2023
10
Where "Random Dates" is populated with:
D1: =WORKDAY(RANDARRAY(10,1,A2,B2),1)
Using this formula returns dates within the range, as expected. However, when setting the Integer (I've also seen this called "whole_number") parameter of RANDARRAY to TRUE, it will sometimes select a date outside of the range (i.e., the next business date above the range). See:
D1: =WORKDAY(RANDARRAY(10,1,A2,B2,TRUE),1) Can (and sometimes does) return "2/1/2023" in the spill.
I've tried to look up why this may be for dates, because it doesn't react the same way with numbers. One thought is it has something to do with when it converts the dates selected to integers when INTEGER=TRUE, which may be because it's including time serials in the function somewhere? I'm not sure.
NOTE: "End Date" is not a weekend date and no holidays are used.
I also tried taking WORKDAY away, which doesn't add a date outside of the max value, with either TRUE or FALSE for INTEGER.
I then added type-casted the RANDARRAY as INT:
D1: =INT(RANDARRAY(10,1,A2,B2,TRUE)) which didn't seem to replicate the issue.
But when I added a 5th column with a WORKDAY function in each cell, it then added an additional day again:
E1: =WORKDAY(D1,1) filled down for each of the results.
As soon as I take the TRUE parameter out of cell D1, it goes back to even the values in column E calculating only within the range. This strikes me as Dates passed to RANDARRAY are potentially being calculated with MAX-1 instead of just the MAX provided when INTEGER=FALSE. Which seems like it would be strange behavior.

Difference between previous and current month

I'm trying to calculate the difference between current month and previous month.
The date field in my DB called C_DATE (dd/MM/YYYY), and I'm using in my sheet a date filter in the format: Year(C_DATE)&'-'& Num( Month(C_DATE),'00'). So when the user choose month (for example 2022-05), he will see the difference in the data between May and April.
I've already tried to calculate by:
count ({<Answer_num={">=6"}, C_DATE={">=$(=(MonthStart(Max(C_DATE))))<=$(=(MonthEnd(Max(C_DATE))))"}>}Answer_num) -
count ({<Answer_num={">=6"}, C_DATE={">=$(=(AddMonths( MonthStart(Max(C_DATE)),-1)))<=$(=(MonthStart(Max(C_DATE)))))"}>}Answer_num)
but i'm getting wrong outcome. is it maybe because of the date filter format? What can I do?
Thank you!
I think this is a matter of getting the date format correct and using the proper set operator. This may work:
=Count({1<Answer_num={">=6"}, C_DATE={">=$(=Date(MonthStart(Max(C_DATE)), 'DD/MM/YYYY'))<=$(=Date(MonthEnd(Max(C_DATE)), 'DD/MM/YYYY'))"}>*$} Answer_num)
-
Count({1<Answer_num={">=6"}, C_DATE={">=$(=Date(AddMonths(MonthStart(Max(C_DATE)),-1), 'DD/MM/YYYY'))<=$(=Date(MonthStart(Max(C_DATE)), 'DD/MM/YYYY'))"}>*$} Answer_num)
This adds the =Date(..., 'DD/MM/YYYY') expression to the set expressions so that the formatting matches the format of the [C_DATE] field. We also add the * set operator so that we get the intersection between the selection ($) and our ">=...<=..." set expression.
I'm sort of guess on the use of the intersection operator, it could be that the union operator (+) is the correct one to use in this case.

Google Sheets - IF Statement - Null date (1/1/2500) workaround

I am working on a large nested IF statement that checks several validation points for each row of my sheet. There are several date validations, including chronological order and certain fields not being future dates. However, our system requires that if we must null any dates for processing, that date becomes 1/1/2500, and no matter what I do I cannot seem to get the formula to ignore this date when accounting for future dates or chronology.
//The date cannot be later than the current date - I want this to ignore 1/1/2500
IF(K1<>1/1/2500,"",IF(AND(K1>TODAY()),"Date A cannot be future date",""))
//The two dates must be in chronological order, also ignoring 1/1/2500
IF(U1<>1/1/2500,"",IF(AND(U1>AA1,AA1),"Date A, Date B should be in chronological order",""))
The above approach does not seem to recognize 1/1/2500, even though I got it to work with other dates.
I also tried going with >12/31/2099 (ignore any date greater than 12/31/2099) but it just ignores every date.
Any help would be appreciated.
It looks as though it is failing because K1 is compared to 12/31/2099.
If you use an expression like this in a formula, it will interpret it as an arithmetic expression 12 divided by 31 divided by 2099, which is a very small number, so the greater than test will always be true.
Try starting the formula with Date to convert a year, month, and day into a date.
If(K1>date(2099,12,31)
and you should get the right answer.
See my previous answer for Excel.

postgreSQL increment number in output

I am extracting three values (server, region, max(date)) from my postgresql> But I want to extract an additional 4th field which should be the numerical addition of 1 to 3rd field. I am unable to use date add function as in the database date field is defined as an integer.
date type in DB
date|integer|not null
tried using cast and date add function
MAX(s.date)::date + cast('1 day' as interval)
Error Received
ERROR: cannot cast type integer to date
Required output
select server, region, max(alarm_date), next date from table .....
testserver, europe, 20190901, 20190902
testserver2, europe, 20191001, 20191002
next date value should be the addition to alarm_date
To convert an integer like 20190901 to a date, use something like
to_date(CAST(s.date AS text), 'YYYYMMDD')
It is a bad idea to store dates as integers like that. Using the date data type will prevent corrupted data from entering the database, and it will make all operations natural.
First solution that came to my mind:
select (20190901::varchar)::date + 1
Which output 2019-09-02 as type date.
Other solutions can be found here.

Converting string timestamp into date

I have dates in a postgres database. The problem is they are stored in a string field and have values similar to: "1187222400000" (which would correspond to 07.08.2007).
I would like to convert them into readable dates usind some SQL to_date() expression or something similar but can't come up with the correct syntax to make it work.
There really isn't enough information here for a conclusion, so I propose this 'scientific-wild-ass-guess' to resolve your puzzle. :)
It appears this number is UNIX 'epoch time' in milliseconds. I'll show this example as if your string field had the arbitrary name, 'epoch_milli'. In postgresql you can convert it to a time stamp using this statement:
SELECT TIMESTAMP WITH TIME ZONE 'epoch' + epoch_milli * INTERVAL '1 millisecond';
or using this built-in postgresql function:
SELECT to_timestamp(epoch_milli / 1000)
either of which, for the example '1187222400000', produces the result
"2007-08-15 17:00:00-07"
You can do some of your own sleuthing with quite a few values selected similarly to this:
SELECT to_timestamp(epoch_milli/1000)::DATE
FROM (VALUES (1187222400000),(1194122400000)) AS val(epoch_milli);
"Well, bollocks, man. I just want the date." Point taken.
Simply cast the timestamp to a date to discard the excess bits:
SELECT to_timestamp(epoch_milli / 1000)::DATE
Of course its possible that this value is a conversion or is relative to some other value, hence the request for a second example data point.