I'd like to display the previous year in my Jekyll posts. To get the current year, I just use:
We are in {{ site.time | date: '%Y' }} today
The question is, how do I get the previous year
We were in {{ site.time | date: '%Y' - 1 }}
That last statement doesn't work, hence the question.
You can use the minus filter:
We were in {{ site.time | date: '%Y' | minus: 1 }}
Related
Is there anyway of adding a date from my tables to an date_add? For example, in the code, i want to change 2009-05-25 to a date that exists from a table. Thanks in advance.
select date_format( date_add("2009-05-25",interval 2500 day),"%d - %m - %Y" )
as fire_date;
Just use the column name instead of "2009-05-25"
select date_format( date_add(my_column_name,interval 2500 day),"%d - %m - %Y" ) as fire_date;
The dates in my table are formatted like this Wednesday 17th May 2017 and Saturday 27th May 2017 and I want to convert it to something like this 17/05/2017 and 27/05/2017 and ORDER BY MyDate.
I tried doing it many different ways and did a lot of research for hours but no luck.
$sql="SELECT * FROM table
WHERE 1 = CASE WHEN deliver = 'Completed' THEN 0 ELSE order = '$order' END
ORDER BY STR_TO_DATE(MyDate,"d-m-Y") ASC";
$res=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($res))
{
echo $row['MyDate'];
}
If someone could please help, I would very much appreciate it.
You need to use a proper format when converting string to datetime values
SELECT *,
-- convert to datetime and then format accordingly
DATE_FORMAT(STR_TO_DATE(mydate, '%W %D %M %Y'), '%m/%d/%Y') formatted_date
FROM table1
-- convert to datetime
ORDER BY STR_TO_DATE(mydate, '%W %D %M %Y');
%W - Weekday name (Sunday..Saturday)
%D - Day of the month with English suffix (0th, 1st, 2nd, 3rd, …)
%M - Month name (January..December)
%Y - Year, numeric, four digits
Sample output:
+------+-------------------------+----------------+
| id | mydate | formatted_date |
+------+-------------------------+----------------+
| 2 | Wednesday 17th May 2017 | 05/17/2017 |
| 1 | Saturday 27th May 2017 | 05/27/2017 |
+------+-------------------------+----------------+
Here is a dbfidlle demo
I have a date like:-
Thu Dec 26 05:24:05 UTC 2013
and I want to convert this date like this
26th Dec 2013
I want solution for it.
The date you have is a string and in mysql you need to use str_to_date() in conjunction with date_format() to get the date in a formatted pattern
mysql> select
date_format(
str_to_date(
'Thu Dec 26 05:24:05 UTC 2013','%a %b %d %h:%i:%s UTC %Y'
),'%D %b %Y'
) as date;
+---------------+
| date |
+---------------+
| 26th Dec 2013 |
+---------------+
From a date object, you can individually extract date.
Date dte=new Date();
dte.format(dd.MM..YYYY);
for more information, visit http://www.tutorialspoint.com/java/java_date_time.htm
I'm not even sure if it's possible to do this, as SSRS has alot of limitations.
Suppose I have two entries in my SQL Table:
Name: John Doe
Value: 20
Month: January 2014
Name: John Doe
Value: 30
Month: February 2014
I'm trying to do some conditional formatting depending on if the value went up or down from the previous month.
Right now I'm grouping on Month. Is there a way to somehow compare the previous value in the grouping to the current one? Something like:
=IIF(Fields!Month.Value < (Fields!Month.Value-1) ) ...
This seems like it would just take the value of the current month and give the month before that.
Thoughts?
EDIT: After trying the 'Previous' command, it is getting closer to what I'm seeking.
However... It is comparing fields from other people. (the data is grouped by person, then by month)
For example:
Name: John Doe
Value: 20
Month: January 2014
Name: John Doe
Value: 30 - WOULD BE GREEN BECAUSE 30 > 20
Month: February 2014
Name: Steve Smith
Value: 10 - WILL SHOW RED BECAUSE 10 < 30 (different person)
Month: January 2014
Name: Steve Smith
Value: 20
Month: February 2014
You can do this with the Previous function.
Say I have data like this:
And a table based on this, grouped on month:
I have applied the following expression to one of the textboxes:
=IIf(Previous(Sum(Fields!val.Value), "monthGroup") > Sum(Fields!val.Value)
, "Red"
, "Green")
For me the expression editor showed a syntax error, but it ran fine:
You could adapt this for other formatting requirements.
The year is expected to be picked as current year instead of the 00 year as shown below.
mysql> select str_to_date('Jul 15 12:12:51', '%b %e %T');
+--------------------------------------------+
| str_to_date('Jul 15 12:12:51', '%b %e %T') |
+--------------------------------------------+
| 0000-07-15 12:12:51 |
+--------------------------------------------+
Expected result:
| 2013-07-15 12:12:51 |
Well, that's intended. Quoting the doc:
Unspecified date or time parts have a value of 0, so incompletely
specified values in str produce a result with some or all parts set to
0. [...] “Zero” dates or dates with part values of 0 are permitted unless the SQL mode is set to disallow such values.
It's easy to fix, btw:
select str_to_date(CONCAT(YEAR(NOW()), ' ', 'Jul 15 12:12:51'), '%Y %b %e %T');
-- July, 15 2013 12:12:51+0000
Simple, ugly, but works:
select str_to_date(concat('Jul 15, ', year(now()), ' 12:12:51'), '%b %e, %Y %T');