LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to find/display out last Friday's date of the month (http://www.linuxquestions.org/questions/linux-general-1/how-to-find-display-out-last-friday%27s-date-of-the-month-4175454956/)

sunnysthakur 03-21-2013 02:25 AM

How to find/display out last Friday's date of the month
 
Hello,

Can you please help me find/display out last Friday's date of the month using command in Unix/Linux

jschiwal 03-21-2013 02:43 AM

This seems like a homework question, so I'll hint at the answer. Look at the man page of date. Read the descriptions of the -d argument and the +format.

pan64 03-21-2013 02:44 AM

there is no such command, you need to implement it, for example in perl using localtime

sunnysthakur 03-21-2013 03:21 AM

I tried with date --date with below strings
'2 friday' #This show 2 friday from now
'last friday' #This shows previous firday of month

but this is not showing what i want....

m.a.l.'s pa 03-21-2013 03:49 AM

Last Friday's date of the month:

$ date --date='last friday' +%d
15

m.a.l.'s pa 03-21-2013 04:44 AM

Very cool; for those who are interested, see the OP's thread here: http://ubuntuforums.org/showthread.p...1#post12567241

So, I think this is what was wanted:

Code:

$ date +"$(cal -N |awk '/^Fr/ {print $(NF)}') %B"
29 March

We'll see what the OP says.

onebuck 03-21-2013 08:56 AM

Moderator response
 
Quote:

Originally Posted by sunnysthakur (Post 4915754)
Hello,

Can you please help me find/display out last Friday's date of the month using command in Unix/Linux

Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.

Habitual 03-21-2013 02:01 PM

Code:

date -d "$(date -d "-1 month" +%Y-%m-01) +1 month -1 day" +%m-%d-%Y
02-28-2013

SharpyWarpy 03-22-2013 06:08 PM

Well it has been well over a day since the original post so I have a question for all contributors to this thread. I'm not totally clear what the OP is after but what about the "cal" command? The entire present month is displayed like a calendar and it's easy to see what the date was last Friday. ?? Comments? Am I way off base here?

m.a.l.'s pa 03-22-2013 06:39 PM

Judging by what the OP wrote in the Ubuntu thread that was also started, I assume that what was wanted was a command that would output the date of the final Friday of the current month. In that thread, the OP wrote, "The output date should be 29 march...." I'm guessing that that he didn't want something like echo "29 march", and that simply looking at a calendar wouldn't do, either. :)

jschiwal 03-23-2013 05:36 AM

I had read the problem as the day of the month for "last Friday", instead of the date of the final Friday of the month. Incidentally, "last Friday" is a valid argument for the -d argument.

Being able to clearly express a problem requires a student to first organize his thoughts. This could even lead to a solution. Maybe, for these homework problems, we should ask the original posters to restate the problem clearly and unambiguously if the description is muddled, and then to provide information on what they tried, or a description on how they believe they need to proceed to solve the problem.

sunnysthakur 03-29-2013 03:09 AM

This also works for me

cal 03 2013 | awk 'NR==1 {m=substr($1, 1, 3); y=$2} NF>5 {d=$6} END {print "Friday", m, d, y}'


All times are GMT -5. The time now is 03:36 PM.