Date -D Not Working on Mac

date -d not working on mac

You should try it this way date -j -f "%Y-%m-%d %H:%M" "2015-06-11 12:39" +%s. I've just tried it myself.

The commands for date are a bit different on macs than on a Linux based operating system.

date command on Mac OS

This works:

date -j -vJulm -v20d -v1999y '+%A'

According to the OSX date manual page::

-v
Adjust (i.e., take the current date and display the result of the adjustment; not actually set
the date) the second, minute, hour, month day, week day, month or year according to val. If
val is preceded with a plus or minus sign, the date is adjusted forwards or backwards according
to the remaining string, otherwise the relevant part of the date is set. The date can be
adjusted as many times as required using these flags.

Why date '+%s%N' not working on mac terminal?

%N is a GNU extension to the POSIX standard, as clarified in GNU's own documentation: https://www.gnu.org/software/coreutils/manual/html_node/Time-conversion-specifiers.html

The POSIX version of date, doesn't include %N: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/date.html

If I recall correctly, POSIX-certified systems (and macOS is certified) cannot add custom extensions to POSIX tools to guarantee portability across systems.

Cannot format date in bash mac

This should do the trick

date -j -f '%d %b %Y' '+%A' '13 JAN 1995'

MacOS comes with BSD date, but your command is designed to work with GNU date.

Take a look at BSD strftime(3) before fiddling with the format.

alias command date -d @ can not accept $1 on Mac

aliases can't take parameters. You need to create a function instead.

Date command does not follow Linux specifications (Mac OS X Lion)

This is because OSX and Linux use two different sets of tools. Linux uses the GNU version of the date command (hence, GNU/Linux). Remember that Linux is Linux and OS X is Unix. They're different.

You can install the GNU date command which is included in the "coreutils" package from MacPorts. It will be installed on your system as gdate. You can either use that, or link the date binary with the new gdate binary; your choice.

as.Date() not working with %B on Mac maybe?

I would suggest adding a day value to your string in this way:

#Data
x1 <- c("February 2012", "March 2012", "April 2012", "May 2013", "July 2015")

Code:

#For date
as.Date(paste('01',x1),'%d %B %Y')

Output:

[1] "2012-02-01" "2012-03-01" "2012-04-01" "2013-05-01" "2015-07-01"

Or you can try:

#Format date
format(as.Date(paste('01',x1),'%d %B %Y'),'%B %Y')

Output:

[1] "February 2012" "March 2012"    "April 2012"    "May 2013"      "July 2015" 


Related Topics



Leave a reply



Submit