Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
12-02-2016, 04:24 AM
|
#1
|
LQ Newbie
Registered: Dec 2016
Posts: 1
Rep: 
|
Need to Find First Day of the month from the current date.
Hi There,
I am trying to find the first day from the current date of the month.
For Example:
If current date is 12/2/2016 then,
I should get 'Thu' (i.e first day of the month) as the output.
Thanks in Advance.
|
|
|
12-02-2016, 04:39 AM
|
#2
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,422
|
Sounds reasonable - let's see what you have tried.
|
|
|
12-02-2016, 05:43 AM
|
#3
|
LQ Guru
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 6,282
|
Quote:
Originally Posted by Ris124
Hi There,
I am trying to find the first day from the current date of the month.
For Example:
If current date is 12/2/2016 then,
I should get 'Thu' (i.e first day of the month) as the output.
Thanks in Advance.
|
Interesting. You do not want the date, but only the day of the week short form?
I am eager to see what you have tried.
|
|
|
12-02-2016, 05:48 AM
|
#4
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
You might need some hints. The utility "date" has a good manual page and there you will find a section on date formats. There it is possible to choose how the date is presented, including whether it is just a day name.
|
|
|
12-02-2016, 06:02 AM
|
#5
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep: 
|
Quote:
Originally Posted by Ris124
Hi There,
I am trying to find the first day from the current date of the month.
|
Look at a calendar? Sorry, could not resist.
First day of the current month:
Code:
date -d "-1 month -$(($(date +%d)-1)) days"
Last edited by Habitual; 12-02-2016 at 06:04 AM.
|
|
|
12-02-2016, 08:37 AM
|
#6
|
Senior Member
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,828
|
It's actually pretty straightforward:
Code:
date -d "$(date +%B) 1" +%a
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 09:56 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|