SQite format time values to 2 digits - format

I need to compare time values in an SQLite database;
The problem is that some records the time is in this format:
'8:15'
and some records are in this format:
'08:15'
The field is type varchar(16)
So the time value '08:15' is not the same time as '8:15' according to SQLite
How can I return a field with the value '8:15" as '08:15' or '08:5' as '08:05'?
Thanks

Related

Power BI Measure returning Blank when it shouldn't

I am trying to create a measure that will return a value for the number of issued receipts in the year 2020:
CALCULATE(SUM(Receipts[issued]), FILTER(Receipts, Receipts[Year] = 2020))
However, the measure keeps returning blank, even as a calculated column.
I've also tried
CALCULATE(SUM(Receipts[issued]), FILTER(Receipts, Receipts[Year].Year = 2020))
But that is returning an error saying the syntax for "Year" is incorrect.
The Year column is of datatype Date and is linked to a dimDate table on the Date column.
I am trying to retrieve the value 440,000. What am I doing wrong?
Try this.
CALCULATE(SUM(Receipts[issued]), YEAR(Receipts[Year]) = 2020)

How to update ends_at field of laravel cashier

I want to update ends_at column of subscriptions table. When i use
Carbon::now()
It update perfectly but when is use
Carbon::now()->addCenturies(5);
I am face error
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2520-08-07 11:39:13' for column 'ends_at' at row 1 (SQL: update `subscriptions` set `ends_at` = 2520-08-07 11:39:13, `subscriptions`.`updated_at` = 2020-08-07 11:39:13 where `id` = 1)
i want one subscription for life time due to this i think add centuries. kinldy tell me solution my controller code is
$subscription = $user->newSubscription('default', $plan->plan_id)->create($request->paymentMethod, [ 'email' => $user->email ]);
$subscription->ends_at = Carbon::now()->addCenturies(5);
$subscription->save();
The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of 1970-01-01 00:00:01 UTC to 2038-01-19 03:14:07 UTC. Your given year is 2520 and your MySQL can handle year as max 2038.
Change the migration timestamp to dataTime format as :
$table->timestamp('ends_at');
to
$table->dateTime('ends_at');
It looks like ends_at is meant to be managed for you by Laravel Cashier, not something you modify manually. Reviewing the source code, it is only updated based on other values, not any parameters. It also is not used to set any parameters in Stripe API requests. The cancel_at parameter would seem to most likely mapping.
If you wish to set cancel_at, it takes an epoch timestamp (in seconds). As #sta mentioned above, this has a maximum value of 2147483647, representing a time in 2038.
Note also that Subscriptions will by default continue in perpetuity, so it is not necessary to set an "end date" 5 centuries from now.

Time duration in Google Data Studio

I have some data I collect regarding length of time that's stored in HH:MM format. The data is in relation to sleep patterns (i.e. sleep duration, time fell asleep, etc...).
I am trying to import the data in Google Data Studio (DS) as a numeric variable, but it appears as text. I can see in DS there is a duration (seconds) numeric format, how can I convert a text variable into a numeric one?
It would be easier to convert the fields in a Google Sheet, but I need them as HH:MM for other calculations.
Try this:
0) Create a new Calculated Field
1) Seconds
Use a formula to convert the Time values to a single value in Seconds, where HH:MM:SS represents the field name:
( CAST(REGEXP_EXTRACT(HH:MM:SS, "^(\\d{2})") AS NUMBER ) * 60 * 60 ) + ( CAST(REGEXP_EXTRACT(HH:MM:SS, ":(\\d{2}):") AS NUMBER ) * 60 ) + CAST(REGEXP_EXTRACT(HH:MM:SS, "(\\d{2})$") AS NUMBER )
2) Change Field Type
- Numeric > Duration (sec.)
Credit to Google support community
You can use the TODATE or MINUTE and SECOND function into a calculated field to extract minutes and second from a date. However don't expect to display minutes and second datapoint on a line chart in Data Studio, timeserie charts only support hour-level data at a minimum.

SSRS Report expression setup

I have a dataset with 4 fields (Date,SeccurityName, FiledName, Value). In my dataset query I filter the data to bring only records with a specific value in the filed name(Last Price). Following is a sample of my dataset
Date SecurityName FiledName Value
5/5/2016 A LastPrice 20.01
5/6/2016 A LastPrice 19.8
5/7/2016 A LastPrice 19.9
5/5/2016 B LastPrice 43.1
5/6/2016 B LastPrice 43.5
5/7/2016 B LastPrice 43.7
In this dataset I have data for each security for each business day for the last 5 years.
In my report I need to show in a table The security name , the last value, the value from a month ago, the value from a year ago and the value from three years ago
Security name LastPrice 1M 1Year 3Years
A 20.1 18.8 19.01 16.05
I would appreciate if someone can give me the best way to build this format.
I would group your table on the Security Name. This would aggregate all records with the same security name on the same line.
Then for each date/value column, create an IIF statement to filter for the date that you want:
=MAX(IIF(Fields!Date.Value = Parameters!LastDate.Value, Fields!Value.Value, NOTHING))
The Last Month (and other dates) would be similar:
=MAX(IIF(Fields!Date.Value = DATEADD("M", -1, Parameters!LastDate.Value), Fields!Value.Value, NOTHING))
The MAX is used to aggregate the NOTHINGS with the Values.
I think it would be best to have the Last Date as a parameter (with a default of yesterday?) to make it easier to create the expressions and you would also have the ability to look at past dates if you ever have the need.

Retrieve database records between two weekdays

I have several records in my database, the table has a column named "weekday" where I store a weekday like "mon" or "fri". Now from the frontend when a user does search the parameters posted to the server are startday and endDay.
Now I would like to retrieve all records between startDay and endDay. We can assume startDay is "mon" and endDay is "sun". I do not currently know how to do this.
Create another table with the names of the days and their corresponding number. Then you'd just need to join up your current table with the days table by name, and then use the numbers in that table to do your queries.
Not exactly practical, but it is possible to convert sun,mon,tue to numbers using MySQL.
Setup a static year and week number like 201610 for the 10th week of this year, then use a combination of DATE_FORMAT with STR_TO_DATE:
DATE_FORMAT(STR_TO_DATE('201610 mon', '%X%V %a'), '%w')
DATE_FORMAT(STR_TO_DATE('201610 sun', '%X%V %a'), '%w')
DATE_FORMAT(STR_TO_DATE('201610 tue', '%X%V %a'), '%w')
These 3 statements will evaluate to 0,1,2 respectively.
The main thing this is doing is converting the %a format (Sun-Sat) to the %w format (0-6)
well i don't know the architecture of your application as i think storing and querying a week day string is not appropriate, but i can tell you a work around this.
make a helper function which return you an array of weekdays in the range i-e
function getWeekDaysArray($startWeekDay, $endWeekDay) {
returns $daysArray['mon','tue','wed'];
}
$daysRangeArray = getWeekDaysArray('mon', 'wed');
now with this array you can query in table
DB::table('TableName')->whereIn('week_day', $daysRangeArray)->get();
Hope this help

Resources