Date from GNU to BSD


 
Thread Tools Search this Thread
Operating Systems Linux Date from GNU to BSD
# 1  
Old 11-21-2010
Date from GNU to BSD

Dear all,

This should be simple but I cannot figure it out despite reading all the man pages. Could someone please help me translate this code (GNU date) to one that can be read by BSD date?:

myDate=$(date -d "$h -$l days" +%Y/%m/%d),

where h is a variable of the form DD/MM/YYYY, and l is a simple integer.

So basically, I want to take the date that is stored in h, add l days to it, and format it as YYYY/MM/DD.

Alternatively, is there a way to force my mac to use GNU date instead of BSD date?

Thank you!
Tom
# 2  
Old 11-21-2010
You need to install gnu date for OSX - there is no way to make other date utilities to behave like GNU date

try MacPorts:
The MacPorts Project -- Home
# 3  
Old 11-22-2010
GNU date makes a lot of problems simple to the point any other system feels lacking without it. "How do I translate this date?" "Use GNU date" "I don't have GNU date" "Use this 9-page shell script, then (but not on leap years!)"
# 4  
Old 11-22-2010
Dear all,

Thank you for your replies. I found a solution with BSD date, though admittedly it is not as pretty as with GNU date. I am posting here in case someone finds it useful one day:
GNU version:
Code:
myDate=$(date -d "1/1/1902 +$l days" +%Y/%m/%d)

BDS version:
Code:
myDate=$(date -j -v+"$l"d -f "%m/%d/%Y" "1/1/1902" +"%Y/%m/%d")

Cheers,
Tom
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bug in Gnu date?

So as I write this today is two days after the clocks go back here in the UK. I have a script that worked last week. Yesterday it developed a bug. I eventually found the culprit is Gnu Date. $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.5 LTS... (10 Replies)
Discussion started by: apmcd47
10 Replies

2. UNIX for Advanced & Expert Users

Regarding question for GNU date

Hello All, Greetings all !! I have a query here, following are the points on same(Adding today's is 31st August 2016 for future reference). 1st Scenario: So while doing some work on GNU date, I wanted to check what was the month(in numbers) by GNU date so I have done following. date... (2 Replies)
Discussion started by: RavinderSingh13
2 Replies

3. Shell Programming and Scripting

GNU & BSD Makefile Directives & Conditions Compatibility

Firstly, I would like to apologize if this is not the appropriate sub-forum to post about GNU/BSD makefile scripting. Though my code is in C++, because I am focusing on the makefile I thought it would go better in shell scripting. Please correct me if I am wrong. Secondly, I am not interested in... (0 Replies)
Discussion started by: AntumDeluge
0 Replies

4. UNIX for Dummies Questions & Answers

Getting date -1 day not using GNU date

It's easy as pie to get the date minus one day on opensolaris: date -d "-1 day" +"%Y%m%d"run this command on our crappy Solaris 10 machines however (which I'm guessing doesn't have GNU date running on it) and you get: date: illegal option -- d date: illegal option -- 1 date: illegal option --... (5 Replies)
Discussion started by: rich@ardz
5 Replies

5. Shell Programming and Scripting

Howto: easy date range iteration/counting on GNU systems in the shell

Should work in any shell, but requires GNU date, although GNU date seems only to be happy for input dates between 1902 and 2037, inclusive (49673 days). Assume $a and $b hold two dates, e.g. set a=2010-03-27 set b=2010-04-04 Marginally faster: iterator: seq -f "$a +%1.0f days" 1 50000 |... (0 Replies)
Discussion started by: laddiebuck
0 Replies

6. UNIX for Dummies Questions & Answers

BSD equivalent of GNU parted

I use GNU (parted)set to change boot flags when doing multibooting. Alas, FreeBSD does not have GNU parted, out of the box. Is there a way to set/remove flags quickly and easily from the command line in BSD? I'm still learning all the 'unique' BSD utilities. (7 Replies)
Discussion started by: uiop44
7 Replies

7. BSD

Anyone using GNU BSD?

Is anyone using or planning to use GNU BSD in production yet? I'd like to hear experiences. (Debian GNU/NetBSD) (8 Replies)
Discussion started by: vpsville
8 Replies

8. UNIX for Dummies Questions & Answers

GNU Date

I know there are some posts on getting the time with milliseconds included and I realize unix may not be the best on this. I have seem some posts where its advised to install the GNU date. Any one know where I can download this as I am struggling to find it. Alternatively - if you have... (5 Replies)
Discussion started by: frustrated1
5 Replies

9. BSD

for linux and BSD users interested in Unix system V/bsd

for all you unix/linux interested heres an online book for free that covers the basics of BSD SysV Unix commands and applications . giving the average linux user a perspective on the differences in context of the two operating systems and for BSD users covers material as a refernce guide. ... (0 Replies)
Discussion started by: moxxx68
0 Replies
Login or Register to Ask a Question