Jekyll post.date or site.date seems to automatically have the timezone mentioned, is there any way I could change this? Or at least change timezone to UTC?
*In Linux Env
You can define the timezone in _config.yml like this:
timezone: UTC
See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for other values (TZ column)
Use the Liquid date filter to format the date however you like:
{{ post.date | date: "%a, %b %d, %y" }}
>
Mon, Oct 10, 16
Related
This is my code:
{{ date ('M-d-Y',strtotime($page->created_at)) }}
The date shows up like this: May-23-2018
How can I modify the code so the date shows up like this: Posted on May 23, 2018
All character meaning : http://php.net/manual/en/function.date.php
You can change symbols in your format how ever you like as long as you have correct characters(from table).
<span>Posted on {{ date('M d, Y',strtotime($page->created_at)) }}</span>
Also Laravel comes wihh Carbon extension for DateTime and is easy to use for working with dates: https://carbon.nesbot.com/docs/
You can solve this in 2 ways:
Simple way: Have 3 variables for a date, month and year and create the string the way you want.
Use date_format: Check https://www.w3schools.com/php/func_date_date_format.asp
you can try this.I hope it will help you.
{{ date("F jS, Y", strtotime($page->created_at)) }}
I am not familiar with timestamp format much.
I have a text for example
'Jul 19, 2013 12:00 pm'
I want to store it to mysql. What format of this timestamp is in MySQL and how should I format it properly in perl before passing it to mysql.
Thanks.
What is the format of timestamps in MySQL?
I highly recommend that you read the MySQL manual. You'll get your answers much faster than by posting a question on StackOverflow. From the docs:
TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
As you can see, the format is YYYY-MM-DD HH:MM:SS.
As ysth points out in the comments, MySQL also has a DATETIME data type:
MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
Several things to note:
DATETIME and TIMESTAMP both use the format YYYY-MM-DD HH:MM:SS
The range of dates supported by DATETIME is much larger than the range for TIMESTAMP
TIMESTAMP converts values to UTC for storage and back to the local time zone on retrieval; DATETIME does no time zone conversion
If you aren't already wedded to the TIMESTAMP data type you might consider using DATETIME instead, depending on what kind of data you're trying to store. See this StackOverflow question for more details on DATETIME vs. TIMESTAMP.
How should I format it in Perl before passing it to MySQL?
To convert date/time strings to different formats in Perl, you can use the core (since v5.9) module Time::Piece:
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use Time::Piece;
my $date = 'Jul 19, 2013 12:00 pm';
my $t = Time::Piece->strptime($date, '%b %d, %Y %I:%M %p');
say $t->strftime('%F %T');
# 2013-07-19 12:00:00
It's not clear from your example date string whether the day and hour are zero-padded. The above example assumes a format like
Oct 01, 2013 05:00 am
where days and hours less than ten begin with a zero. If your input format is actually
Oct 1, 2013 5:00 am
then you need to change the format string passed to Time::Piece->strptime. A list of format specifiers can be found in the man page for strftime.
Time::Piece has been a Perl core module since 5.9. It provides a convenient way to parse any time format input (with strptime()) and produce a differently formatted output (with strftime().
#cat ./tconv
#!/usr/bin/env perl
use strict;
use warnings;
use Time::Piece;
my $t = Time::Piece->strptime( shift, "%b %d, %Y %I:%M %p" );
print $t->epoch, "\n";
print $t->strftime( $t, "%Y/%m/%d %T %z" ), "\n";
#./tconv "Jul 19, 2013 12:00 pm"
1374235200
Fri Jul 19 12:00:00 2013
I'm trying to parse some dates in a MySQL table and I cannot get STR_TO_DATE to play nicely:
SELECT STR_TO_DATE('Tue Feb 12 17:59:59 EET 2013', '%a %b %e %T EET %Y')
will return null.
How can I make it ignore the EET text? I don't need the timezone information.
UPDATE: The MySQL server version is 4.1.14
I think it ONLY works on 5.x (tried on 5.5.x) because of parser which can skip matched templates in string while it was not implemented in 4.x.
You can try the following statement and it would be fine in 5.x but not 4.x:
SELECT STR_TO_DATE('Tue XX Feb 12 17:59:59 SOME_DATA 2013', '%a XX %b %e %T SOME_DATA %Y')
So the best thing you can do is to follow your workaround (replace unwanted substring).
Sidenote: MySQL doesn't have concept of time zones. So MySQL doesn't care and doesn't apply any changes during date conversion if initial string contains UTC, EET, FET and so on.
SELECT STR_TO_DATE(CONCAT(LEFT('Wed Nov 28 20:41:25 GMT 2018',19), RIGHT('Wed Nov 28 20:41:25 GMT 2018',5)), '%a %b %d %H:%i:%s %Y');
This will work nicely and treats the 'GMT' as a wildcard. In each case, the timezone is fixed to three characters.
The names of days and months handled by %a and %b are governed by your server connection's locale setting. I am guessing from your name and timezone that you have some users whose native language isn't 'en_US', the default and the language of "Tue" and "Feb."
Give this command to see your locale setting:
SELECT ##lc_time_names;
You might try issuing
SET lc_time_names = 'en_US';
immediately before issuing the command in your question that's failing, then issuing
SET lc_time_names = 'ru_RU';
or whatever is correct for your users immediately afterwards.
I'm importing an rss feed into MySQL 5.1 via wget and LOAD DATA INFILE.
This is all working well, but, I'm having problems converting the date & time in the rss feed to a datetime col in mysql.
An example date from the feed is:
Sat, 19 Jan 2013 11:10:19 GMT
Any ideas how I can cast or convert this?
Thanks
J.
How about this? using str_to_Date:
STR_TO_DATE('rss_date', '%y-%m-%d')
use STR_TO_DATE
SELECT STR_TO_DATE(DATE_STRING,'%a, %d %b %Y %h:%i:%s')
SQLFiddle Demo
OTHER SOURCE
STR_TO_DATE
Date Formats
I ran this statement in mysql and it returns null on every row:
SELECT STR_TO_DATE('Fri, 22 Jun 2012 03:35:24 +0000', '%a, %e %b %Y %H:%i:%s %%%%%%%%%%') FROm t2;
I don't know the right specifier for the +0000. What should it be?
The +0000 is a time zone offset.
mySQL doesn't understand the concept of time zones, and apparently neither does STR_TO_DATE: the list of date/time format placeholders doesn't mention time zones at all.
If you expect dates from varying time zones, this doesn't seem solvable with the help of mySQL only. You would have to preprocess the date elsewhere to turn it into one that is always UTC (or your local time zone, whatever applies), or if it already is always UTC, ManseUK's suggestion (adding +0000 to your format string so mySQL ignores it) should work.