Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to get first & last day of a month from current date? Post 303041727 by RudiC on Monday 2nd of December 2019 04:45:18 PM
Old 12-02-2019
Did you look into the helpful links at the bottom of this page under "10 More Discussions You Might Find Interesting"?



Howsoever, for your first question, try


Code:
$ date --date='07/20/2019' +"%Y-%m-01"
2019-07-01

, and for the second,



Code:
$ date -d"$(date --date='07/20/2019 +1month' +"%Y-%m-01") -1sec" +%F
2019-07-31

These 3 Users Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

delete files one day old in current month only

i want to delete files that are one day old condition is files should be of current month only ie if iam running script on 1 march it should not delete files of 28 feb(29 if leap year :-)} any modifications to find $DIR -type f -atime +1 -exec rm -f{}\; (4 Replies)
Discussion started by: maverick
4 Replies

2. Shell Programming and Scripting

single digit for day and month on date

hi all, how do i format the date command so it displays day and month in single digits i.e 8 instead of 08 ?? am using the command (in a ksh) : date +%D output i get is 10/08/08 thanks in advance. (5 Replies)
Discussion started by: cesarNZ
5 Replies

3. Shell Programming and Scripting

needs to display month for previous day date

Hello, I wanted to display the month for previous day date. Like, today date is 18-Nov-2008. So the previous date is 17-Nov-2008. The output should be November. If the today date is 1-DEC-2008, then output should be NOVEMBER. If the today date is 1-JAN-2008, then output should be DECEMBER.... (4 Replies)
Discussion started by: govindts
4 Replies

4. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

5. Shell Programming and Scripting

current date - one month in AIX

Hi, i unable to get the last month date in AIX. current date - one month Based on the forums tried but did not find the relevent information. Any help grealy appriciated. Thanks Suri. (3 Replies)
Discussion started by: onesuri
3 Replies

6. UNIX for Dummies Questions & Answers

Move the files between Current day & a previous day

Hi All, I have a requirement where I need to first capture the current day & move all the files from a particular directory based on a previous day. i.e move all the files from one directory to another based on current day & a previous day. Here is what I am trying, but it gives me errors.... (2 Replies)
Discussion started by: dsfreddie
2 Replies

7. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

8. AIX

AIX - Get next month from current date

As said in object, how can i obtain that? In linux i use date -d "1 month" +"%m%Y". Thanks i advance. (8 Replies)
Discussion started by: fabfisc
8 Replies

9. Homework & Coursework Questions

How to minus 2 month from current date?

I am running a script in ksh to get the 2 months back date from system date.The below code is giving correct date output from putty command prompt.But while running the script is .ksh file it is giving the error below.Please suggest. ; d=a; y=a m-=num while(m < 1) {m+=12; y--}... (1 Reply)
Discussion started by: hini
1 Replies

10. UNIX for Beginners Questions & Answers

Replace date in file every day with current date

I Have text like XXX_20190908.csv.gz need to replace Only date in this format with current date every day Thanks! (1 Reply)
Discussion started by: yamasani1991
1 Replies
CHEWMAIL(1)						User Contributed Perl Documentation					       CHEWMAIL(1)

NAME
chewmail - mail archiver SYNOPSIS
chewmail [OPTIONS] <MAILBOX> ... DESCRIPTION
chewmail is a program for archiving mail. It is inspired by the by the Python-based archivemail, but with more useful semantics. All mail is archived to the mailbox specified with the --output-box switch, in mbox format. It can read mailboxes in mbox, Maildir and MH formats. Internally, chewmail uses Mail::Box, so it support file names and URLs supported by that module. OPTIONS
-o mailbox-format, --output-box=mailbox-format The mailbox to archive messages to. The mailbox is run through the Date::Format module, so it supports all it's conversion specifiers. The date and time is relative to the messages timestamp, or the current time if the timestamp is impossible to determine. A sample of the conversion specifiers follows: %% PERCENT %b month abbr %B month %d numeric day of the month, with leading zeros (eg 01..31) %e numeric day of the month, without leading zeros (eg 1..31) %D MM/DD/YY %G GPS week number (weeks since January 6, 1980) %h month abbr %H hour, 24 hour clock, leading 0's) %I hour, 12 hour clock, leading 0's) %j day of the year %k hour %l hour, 12 hour clock %L month number, starting with 1 %m month number, starting with 01 %n NEWLINE %o ornate day of month -- "1st", "2nd", "25th", etc. %t TAB %U week number, Sunday as first day of week %w day of the week, numerically, Sunday == 0 %W week number, Monday as first day of week %x date format: 11/19/94 %y year (2 digits) %Y year (4 digits) -d days-old, --days=days-old Only archive messages older than than this many days. -D date, --date=date Only archive messages old than this date. The date can be any date understood by Perl's Date::Parse module. -R, --only-read Only archive messages that are marked seen or read. --delete-immediately Synchonize the mailboxes after every message is moved. This will be substantially slower but may provide better recovery for some mail- box formats in the event of a crash. --preserve-timestamp Preserve the atime and mtime of the input mailbox. This only affects file-based mailboxes, such as mbox. -n, --dry-run Go through all the motions of archiving the mail, but don't actually change any mailboxes. -v, --verbose Output more informational messages. Use multiple times for more verbosity. -q, --quiet Don't output any messages other than error messages. -V, --version Print the version number then exit. -h, --help Print usage information then exit. EXAMPLES
Archive two day old messages in inbox to inbox-old: chewmail --days 2 -o inbox-old inbox Archive read messages to a mailbox named the year-month of the message: chewmail --only-read -o %Y-%m inbox SEE ALSO
archivemail(1), Date::Parse, Date::Format, Mail::Box AUTHOR
Eric Dorland <eric@kuroneko.ca> perl v5.8.8 2006-08-15 CHEWMAIL(1)
All times are GMT -4. The time now is 03:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy