Duration data type in TimeIntervalDto object - clockify

I am creating a database to store time entries that have been created in Clockify, I need to declare a data type for the duration field. A string is returned in the TimeIntervalDto and an example provided in the API documentation is "PT1M4S" or "PT1H30M15S". This is obviously a meaningful string if you know how to decode it.
The example given in the API documentation is:
"timeInterval": {
"duration": "PT1M4S", (Example: PT1H30M15S - 1 hour 30 minutes 15 seconds)
"end": "2018-06-12T14:01:41Z",
"start": "2018-06-12T14:00:37Z"
},
My questions are:
How to I translate duration to something meaningful; and
What is the maximum size I would need to cater for, assuming that I'm using varchar, or nvarchar as the data type?

You are working with the ISO 8601:2004(en) duration ISO format.
You have a pattern like the follow: "PnnYnnMnnDTnnHnnMnnS"
In detail:
The letter P represent a Period Format
Each letter represent a different value, for example if you want to indicate a period of two year, use 02Y.
For hours use the letter T.
So for your question:
If you can use C# languange before saving to database you can decode de pattern using something like this:
String pattern = "PT1H30M15S";
TimeSpan ts = System.Xml.XmlConvert.ToTimeSpan(pattern); //Use System.Xml because it works with ISO 8601:2004
You can look for further information on in the ISO webpage. https://www.iso.org/obp/ui/#iso:std:iso:8601:ed-3:v1:en

If you are using Postgres Database, you can create a new column based on end and start columns. So you don't need to create a new column just for the duration as it is already implicit with the other two columns.
If you want to get the durations you could do this query:
SELECT (t.end - t.start) as "duration", t.start, t.end from t
This will return you a new column "duration" in interval type.
If you really want to create a new column you could do a SQL trigger to fill a column "duration" of type interval using "start" and "end" columns every time a new entry is added to the table.

Related

How to handle and convert null datetime field into unixtime stamp in Scala

I have some code snippet as below that is not accepted by Scala, it would be appreciated if someone can help to fix it, thanks.
train_no_header is an RDD generated from a csv file, its first line is shown as below:
scala> train_no_header.first
res4: String = 87540,12,1,13,497,2017-11-07 09:30:38,,0
Now, I want to generate another RDD to parse and transform records with null or empty value for the 6th field which should be a DateTime (in the above sample the field is empty), some records might have that and some might not, for those having that, the format is same as 5th which is a UTC DateTime.
I need to calculate the delta between the two DateTime, I plan to convert them into Unixtime format, that being said, the final RDD should have both the two date fields converted into Unixtime format.
So my question is:
with the sample data and format, how do I create the RDD with the needed result?
for records with empty value in the 6th field, how should I handle it so that no exception would be generated in the future query in data frame (which is what I intend to work in)
Thank you very much in advance, any clue is appreciated.

USQL reading last n days when file name pattern does not have day part

In data lake I have file names with pattern yyyyMM_data.csv. Now I want to read previous 3 days data. I am using below code -
DECLARE #ReportDate DateTime= DateTime.Parse("05/08/2017");
DECLARE #FeatureSummaryInput string=#"/FolderPath/{InputFileDate:yyyy}{InputFileDate:MM}_data.csv";
#FeaturedUsed =
EXTRACT Id string,InputFileDate DateTime
FROM #FeatureSummaryInput
USING Extractors.Csv(silent : true, skipFirstNRows : 1);
#FeaturedUsed=
SELECT *
FROM #FeaturedUsed
WHERE InputFileDate BETWEEN #ReportDate.AddDays(-3) AND #ReportDate;
If I run above code it runs with empty input. Please let me know if I am missing something. Why it is not reading correct file?
It seems like we need to must have "day" in file name pattern to work this.
Possibly I am missing something but, as you cast InputFileDate to DateTime it defaults to the first of the month, as no day is specified. For your test ReportDate set to 05/08/2017, your WHERE clause basically evaluates to Between 2017-08-02 And 2017-08-05, which will never be true.
Where do you expect the day element to come in with your files structured as yyyyMM?

datatype in the table should be Date/time or short tgext?

I am desiging dataentryform in access . I made tables and the datatye of one field is Date/time but in property field in format I put mm.\yyyy to get month and year . how should I define input mask for it? I want to see --.----
when I enter data in form I can see calender beside this field but I have to choose day as well I dont want to choose day however the day that I chose doesnt save in table but I have to choose day aw well.
more explaination: I have 2 fields that should define as mm.yyyy .one field is (start of project example 01.2010) and the next field is end of project which also has the same format mm.yyyy (03.2015).
and later I want to get a query which shows duration of project ( end of project - start of project) . so I should also do calculation according to my data.
but I dont know what kind of data type should I define in the table for these two fields. at first I tried Date/Time . but I couldnt find suitable format. then I changed it to short text and I entered 00.0000 in input mask.
what is the best solution because I have to calculate duration of project according to these two fields later? (in queries)
There are many ways around this. One is simply to allow the user to type freely in an unbound textbox, then validate/correct before updating.
Another is to have two/three juxtaposed textboxes for year-month(-day), then build the date value with DateSerial(y, m, d).
in VBA, mm/yyyy alone can never form a date value, so must silently add a day somehow.
Input masks should be avoided as they are a prime hate object for users.
If you insist, you can get an idea how to handle this from my article:
Entering ISO formatted date with input mask and full validation in Microsoft Access
It assumes the ISO sequence because year-month determines the possible day values.
Addendum:
Though decimal months is not an exact measure due to the varying day counts of the months, you will get pretty close with this function:
Public Function DecimalMonths( _
ByVal Date1 As Date, _
ByVal Date2 As Date) _
As Double
Dim Part1 As Double
Dim Part2 As Double
Dim Months As Double
Dim Days1 As Integer
Dim Days2 As Integer
Days1 = Day(DateSerial(Year(Date1), Month(Date1) + 1, 0))
Days2 = Day(DateSerial(Year(Date2), Month(Date2) + 1, 0))
Months = DateDiff("m", Date1, Date2)
Part1 = (Day(Date1) - 1) / Days1
Part2 = (Day(Date2) - 1) / Days2
Months = Months - Part1 + Part2
DecimalMonths = Months
End Function
Please note, that the count from 2017-04-15 to 2017-06-01 is 1.53
while it would be 1.5 from 2017-04-16 to 2017-06-01.

MDX Compare DateTime attribute

I´m new to MDX and I have a simple question. I work with the TFS Cube it is named as Team System. My problem:
I have an IIF expression where I want to check additional my expression with an AND operator. There I want to compare two DateTime objects. The report should only show me the data from the actual date. Here my code:
IIF(ISEMPTY(SUM(YTD(
[Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember),
[Measures].[EffectivelyValue]))
AND[Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember < Now()
, [Measures].[EffectivelyValue]
, SUM(YTD(
[Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember),
[Measures].[EffectivelyValue]) )
Planned Week is a self created field which has the DateTime datatype. The Now() function has also a DateTime datatype so the comparision should be right but it happens nothing.
Thanking you in anticipation
Eugen
Hierarchy members in MDX have a data type of 'member', and do not have a 'primitive' data type like datetime, string, or integer. Only member properties have 'primitive' data types. You could either define a property like datetime of your week attribute. Assuming you are SQL Server Analysis Services, this would be done via relationships.
Or you could use string operations to extract the date information from the UniqueName property which avoids having to change the cube. The UniqueName contains the data that you defined as the key in your cube design. Assuming your week hierarchy members have a key from which you can extract something like 20130820 for August 20, 3013 via string functions (I just will use Mid(, 30, 8) as an example below), you could do something like
CLng(Mid([Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember.UniqueName, 30, 8))
<
CLng(Format(Now(), "yyyymmdd"))
You will have to check what exactly the CurrentMember.UniqueName shows in your cube to adapt the above code.
And finally, you could of course also use string methods to extract the relevant parts from the UniqueName and then the CDate function on that to compare to an unchanged Now(), i. e. do all operations on the left side of the <.
Hello thank you very much for you answer. I tried:
Mid([Work Item].[xxxx_PlannedWeek__HierarchyByWeek].CurrentMember.UniqueName,58,10)
shows e.g. 2013-07-21, 2013-07-28 (it shows the week endings)
so I tried this:
AND CLng(Mid([Work Item].[xxxx_PlannedWeek__HierarchyByWeek].CurrentMember.UniqueName,58,10))
<CLng(Format(Now(), "yyyy-mm-dd"))
But it happens nothing. If I execute it in a single way it shows everywhere "true". But I have datasets with dates which are e.g. > 2013-08-23. So there should be false values too.
EDIT: OK I solved the problem. The
Format(Now(), "yyyy-mm-dd")
must be
Format(Now(), "yyyy-MM-dd")

SELECT clause with a DATETIME column in Sybase 15

I'm trying to do a query like this on a table with a DATETIME column.
SELECT * FROM table WHERE the_date =
2011-03-06T15:53:34.890-05:00
I have the following as an string input from an external source:
2011-03-06T15:53:34.890-05:00
I need to perform a query on my database table and extract the row which contains this same date. In my database it gets stored as a DATETIME and looks like the following:
2011-03-06 15:53:34.89
I can probably manipulate the outside input slightly ( like strip off the -5:00 ). But I can't figure out how to do a simple select with the datetime column.
I found the convert function, and style 123 seems to match my needs but I can't get it to work. Here is the link to reference about style 123
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.blocks/html/blocks/blocks125.htm
I think that convert's slightly wrongly documented in that version of the docs.
Because this format always has century I think you only need use 23. Normally the 100 range for convert adds the century to the year format.
That format only goes down to seconds what's more.
If you want more you'll need to past together 2 x converts. That is, past a ymd part onto a convert(varchar, datetime-column, 14) and compare with your trimmed string. milliseconds comparison is likely to be a problem depending on where you got your big time string though because the Sybase binary stored form has a granularity of 300ms I think, so if your source string is from somewhere else it's not likely to compare. In other words - strip the milliseconds and compare as strings.
So maybe:
SELECT * FROM table WHERE convert(varchar,the_date,23) =
'2011-03-06T15:53:34'
But the convert on the column would prevent the use of an index, if that's a problem.
If you compare as datetimes then the convert is on the rhs - but you have to know what your milliseconds are in the_date. Then an index can be used.

Resources