ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, so a program was prebuilt before my time here that names files (I assume) with the 'date +%j' because they all correspond to the current year, but in a 001-365 format. "Filename.212.gz" for example. I need to be able to grab one of these files and parse through it (done) but now they want it pretty with the actual date i.e. "July 28". Is there any quick way to use the linux 'date' cmd to my advantage? I would love to use something in place instead of taking up memory... I don't mind writing it out, but just thought I would ask. Thanks!
I've found a TON of programs on google about the gregorian calendar and conversions, but if there is an easier way - I'm all for it.
I've always done this by passing epoch time of the # of days given, adjusted by timezone through localtime and grab the appropriate field in the resulting array.
This certainly saves some effort, thanks for the tip Mr C
You can add a final parameter for specifying daylight saving time. isdst value of 0 or 1. I figured the OP wouldn't care about this since we're assuming midnight here.
Okay, I have another problem... This worked GREAT on my Suse and Ubuntu boxes, but I have a FREEBSD machine that the "date -d" is all screwed up... I found the man pages, but if anyone can help do the same thing as above, but with the freebsd version i would GREATLY appreciate it.
According to the man page, the -d option has a totally different meaning on FreeBSD. On Unix machines, where the -d option did not exist, I used a custom Fortran code which accepted a date in yyyymmdd format and a number of days to add or subtract. If you are experienced in programming you can try to write a C or a Fortran code to do the required operations. Or eventually you can write some function in python or in another scripting language that can manage dates.
Or eventually install the GNU date on FreeBSD, but sincerely I don't know if it is possible or if there is a precompiled package that provides such functionality.
You've run into the standard cross-platform utilities problem. This is an important requirement to mention at the beginning of your problem. Otherwise, as you found out, solutions won't work.
I generally try to keep portability in mind when I propose solutions.
Or eventually install the GNU date on FreeBSD, but sincerely I don't know if it is possible or if there is a precompiled package that provides such functionality.
I would highly recommend this route. `date` is tried and true and will take things into account such as leap years, etc. You can install the GNU utilities on damn near everything including Solaris.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.