printing 'date' in unix - date

The command echodate gives output : Sun Aug 20 08:14:50 2017.
I want the date format in : Aug 20.
I tried command : echodate|awk '{print $2, $3}', which outputs to what I want: Aug 20
Is there any other method?

If you look into the date man page, you'll see it's quite capable of delivering what you want without passing the output through a textual filter - you can just use + to specify the output format, such as:
pax> date +"%b %d"
Aug 20

Related

Google Sheet convert time format to another

Whenever I extract raw data from this specific tool I am getting the date format of
Fri Sep 2 10:29:50 2022
Fri Sep 9 10:31:01 2022
Mon Sep 12 10:32:28 2022
and I am having a hard time converting it to this kind of format in Google Sheet
9/2/2022 10:29
9/9/2022 10:31
9/12/2022 10:32
Already tried using different of formating but still can't convert it to the above format.
use:
=ARRAYFORMULA(IF(A1:A5="",,REGEXREPLACE(TRIM(A1:A5),
"(.*) (.*) (.*) (.*) (.*)", "$2/$3/$5 $4")*1))
then do:
Date value
=ArrayFormula(IF(A2:A="",,
DATEVALUE(REGEXEXTRACT(TRIM(A2:A), "(.+\d{1,2}) \d{1,2}:")&" "&REGEXEXTRACT(A2:A, " (....\z)"))+
TIMEVALUE(REGEXEXTRACT(TRIM(A2:A), " (\d{1,2}:\d{1,2}:\d{1,2}) "))))
Custom date and time formats
Custom number formats

How to print date in MM/DD/YYYY formate in unix?

I'm new to unix and I'm trying to run print the date using:
echo "Purchase date: `date`"
but I keep getting the date in the format
Purchase date: Fri Oct 2 12:21:26 EDT 2020
but I'm trying to get it in the format of MM/DD/YYYY
A quick google search will show you lots of options but I believe you want something like: ~$ date +%m/%d/%Y
~$ 10/02/2020
%[a-z] represents formatting options.
%m - month (01..12)
%d - day of month
%Y - Full Year
'/' - Delimiter
You can see all of the date formatting options by using the help command:
~$ date --help

Date value as float - Apple's iWork Numbers 09 - internal XML

I am writing a script in PHP which will convert Numbers file into HTML table, but I can not figure out which format is used for date storage. The date cell tag looks like
<sf:d
sf:s="SFTCellStyle-128"
sf:w="84.074219"
sf:h="14"
sf:cell-date="371397519.99999952" />
so the date must be in sf:cell-date attribute, but I can not figure out how to convert it into human readable format. Any ideas? I have never seen date value as float number.
As written in a comment, it is the number of seconds since 01/01/2001 at 00:00:00. Equipped with that knowledge and because this goes hand in hand with the UNIX Epoch all you need to do is to define and use the offset. It should be compatible with nearly every of the existing PHP date functions and objects, for example with date:
define('CELL_DATE_EPOCH_OFFSET', 978307200);
$sf_cell_date = 371397519.99999952;
echo date('r', CELL_DATE_EPOCH_OFFSET + $sf_cell_date);
The output of this little script is (in my timezone):
Mon, 08 Oct 2012 15:58:39 +0200
I hope this is helpful. 978307200 is the unix timestamp for 01/01/2001 00:00:00 UTC, you can get with PHP for example with the following code-example:
$base = new DateTime('01/01/2001 00:00:00 UTC');
echo $base->getTimestamp(), "\n";
in case that was your problem.

Perl equivalent of PHP's strtotime()?

I realize that Perl has strftime, which allows you to pass a formatting object. The functionality I'm wondering if I can find is more like the following (from PHP):
$string1 = "Jun 6, 2012";
$string2 = "June 06 2012";
if (strtotime($string1) == strtotime($string2)) {
echo "BLAMMO!";
}
// will echo "BLAMMO!"
The reason for this is a business need in which user-provided dates need to be compared for validation and extended logic (does this date fall within another daterange also provided, etc). Now, I realize I can write an entire library devoted to doing this, and I realize there are any number of potential pitfalls with date-parsing and you should never trust user input, but here are some basic assumptions.
The input is actually output from any number of software packages that conform to their own internal specifications for date formatting. They all follow some standard, but those standards are not uniformly normalized between programs. That being said, I should always be comparing two dates from the same program, but I may never know what format they may follow.
I realize the standards of any given system are likely to be different, but the assumption here is that we're feeding ALL of our dates into the same thing, so we can trust a consistent implementation, hopefully something in CPAN or another easily updated module.
Date::Parse supplies str2time, which does this.
The documentation lists some examples that the module can parse:
1995:01:24T09:08:17.1823213 ISO-8601
1995-01-24T09:08:17.1823213
Wed, 16 Jun 94 07:29:35 CST Comma and day name are optional
Thu, 13 Oct 94 10:13:13 -0700
Wed, 9 Nov 1994 09:50:32 -0500 (EST) Text in ()'s will be ignored.
21 dec 17:05 Will be parsed in the current time zone
21-dec 17:05
21/dec 17:05
21/dec/93 17:05
1999 10:02:18 "GMT"
16 Nov 94 22:28:20 PST
The standard for date/time manipulation in Perl is the DateTime project.
https://metacpan.org/pod/DateTime
strptime for Perl can be obtained in the core module Time::Piece. This offer a core module solution whereas the rich DateTime module unfortunately isn't part of core Perl.

Convert seconds to date from Jan 01 1901 in unix/linux

im trying to convert a time stamp in seconds from Jan 01 1901 to the current date.
for example,
time stamp 3465468225 translate to a date in 2010. does anyone know of a way to do this in unix/linux? thanks.
In R, it is as simple as this:
> as.POSIXct(3465468225, origin="1901-01-01")
[1] "2010-10-25 15:03:45 CDT"
>
This uses appropriate wrappers around C-level calls gmtime() / localtime() plus time formatting via strftime().
On GNU and POSIX systems you can obtain the date string using seconds since Epoch (1970-01-01 00:00:00 UTC) as:
$ date --date=#1289495920
Thu Nov 11 12:18:40 EST 2010
You should handle the offset since Jan 01 1901 yourself.