Angular date pipe subtracts a day from the actual date value - angular6

I am not sure If I need to add anything here. I have a table with a date column. When the date column gets processed through the Angular date pipe, just to change the format to display, it subtracts a day from the actual date. I checked it without adding the date pipe, I get the actual date. What could be wrong?
<div *ngSwitchCase="'pending'" style="color:#367db9">
{{ workOrder.postDate | date: 'MMM d, y'}}
</div>

Have you tried it without the custom format?
{{ workOrder.postDate | date: 'MMM d, y'}}
should be the same result as
{{ workOrder.postDate | date }}
and the same as
{{workOrder.postDate | date:'mediumDate'}}
example: https://jsfiddle.net/Scotty3/bdmqxr5y/4757/
and https://next.angular.io/api/common/DatePipe
If not you'll need to check your source date variable.

Related

SQL Query for returning the latest date

If I consider the following:
Customer | Date
100 | 09-06-2021
100 | 17-03-2020
I am trying to find out the most recent date from the above, by using: select MAX(Date) from table, and it is returning 17-03-2020, which is wrong.
How do I get the most recent date as 09-06-2021?
What is wrong is that you are storing the date as a string, not a date.
You can fix your immediate problem by doing:
select max(str_to_date(date, '%d-%m-%Y'))
from t;
But you should really fix the data. Start by putting the date in a canonical format:
update t
set date = str_to_date(date, '%d-%m-%Y');
Then modify the column to the correct data type:
alter table t modify column date date;

sql incorrect date output incorrect

i have a table like this
|id| date |name|
1 23/11/20 jake
2 01/07/20 jhon
3 23/05/20 blake
4 11/02/20 drake
5 1/03/14 crake
i ran a query like this
WHERE date >= '1/07/20' AND date <= '23/11/20'
i expected a result where i would get only the results between those dates
but i got some results which were from 2014
the data type for the date column is varchar
#note i can not change the datatype
how can i only get dates between the two ?
String-wise comparison is the problem: typically, '10/01/19' (Janurary 10th, 2019) is greater than '01/01/20' (January 1st, 2020), because the former starts with 1, and the later with 0.
You need to turn these strings to dates before you can compare them:
where str_to_date(date, '%d/%m/%y') between '2020-07-01' and '2020-66-23'
This is inefficient, because the entire column needs to be converted before the filtering can happen. I would warmly recommend fixing your data model, and store dates as dates.
Side note: your strings need to be consistently formatted as mm/dd/yy for this to work; if you have varying formats - or strings that do not map to valid dates - then you have a bigger problem than what you have asked here.

Extract the year from the given date?

I have a date field create_at in Y-m-d format in my table. I want to extract only the year from that field.
I tried YEAR(create_at) which gives result in comma separated value.
Eg.
2017-5-12 outputs 2,017. I need without the comma.
The YEAR() will provide you integer output only.
SELECT YEAR("2017-06-15");
2017
Ref https://www.w3schools.com/sql/trymysql.asp?filename=trysql_func_mysql_year

MySQL: converting date formats inside of strings

I have a list of file paths and dates stored in a database:
path | date
_____________________________|___________
C:\folder\file1 %Y-%m-%d.csv | 2016-09-14
C:\folder\file2_%M %d %Y.csv | 2016-09-13
C:\folder\file3 %y%m%d.csv | 2016-08-31
The dates in the file paths are according to the STR_TO_DATE format convention.
The dates will change everyday.
I need to write a SELECT query that will return:
result
_________________________________
C:\folder\file1 2016-09-14.csv
C:\folder\file2_Sep 14 2016.csv
C:\folder\file3 160831.csv
I don't want to end up writing a never-ending REPLACE query with all the possible scenarios:
REPLACE(... REPLACE(REPLACE(path,'%Y',YEAR(date)),'%d',DAY(date))...)
Is there a way to do this with a MySQL built-in function?
You want DATE_FORMAT() here. It should replace format strings it recognizes with their values and ignore everything else.
SELECT DATE_FORMAT(date, path) AS result;
NOTE: %M Will give the full month ("September"), for the abbreviated month ("Sept") use %b.
DEMO: http://sqlfiddle.com/#!9/77b6f7/1

Convert integer of MYYYY into Date in ssrs

I have a field that is a bunch of integers formatted like so:
92014
102014
I would like to convert the field into a datetime of the first of each month. So the newly formated field would be:
9/01/2014 00:00:00
10/01/2014 00:00:00
(or however datetimes would actually get formatted). Can anyone help?
This is how you can accomplish this in an expression:
DateTime.ParseExact(IIF(LEN(Trim(Fields!StringDate.Value)) < 6, "0" & Fields!StringDate.Value,Fields!StringDate.Value),"Myyyy",System.Globalization.CultureInfo.InvariantCulture)