find out month from a date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find out month from a date
# 1  
Old 07-03-2007
find out month from a date

I would like to find out the month from a given date,
how is it possible.
# 2  
Old 07-03-2007
Quote:
Originally Posted by rudoraj
I would like to find out the month from a given date,
how is it possible.
It depends on the format of the given date. Unless we see the format of the date, it is hard to point to one particular solution.
# 3  
Old 07-03-2007
The format of the date is like

Tue Jul 3 06:40:54 EDT 2007

i want to do some manipulation with day, month, year

This is what i am using to process few things

new_day=`date`
month=`echo $new_day | cut -f2 -d ' '`
year=`echo $new_day | cut -f6 -d' '`

now i want to know the which month falls in for the $new_day (1 to 12)

so $new_day is Tue Jul 3 06:40:54 EDT 2007
so how do i find out the month is 07
# 4  
Old 07-03-2007
Quote:
Originally Posted by rudoraj
The format of the date is like

Tue Jul 3 06:40:54 EDT 2007

i want to do some manipulation with day, month, year

This is what i am using to process few things

new_day=`date`
month=`echo $new_day | cut -f2 -d ' '`
year=`echo $new_day | cut -f6 -d' '`

now i want to know the which month falls in for the $new_day (1 to 12)

so $new_day is Tue Jul 3 06:40:54 EDT 2007
so how do i find out the month is 07
What OS are you on ? If you have GNU date, then use

Code:
date -d "Tue Jul  3 06:40:54 EDT 2007" +%m

# 5  
Old 07-03-2007
date +%b

gives Month Name (Jul)

date +%m

gives Month Number(1-12)
# 6  
Old 07-03-2007
>> date -d "Tue Jul 3 06:40:54 EDT 2007" +%m
works perfectly fine
I am using Linux

Thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How bash treats literal date value and retrieve year, month and date?

Hi, I am trying to add few (say 3 days) to sysdate using - date -d '+ 3 days' +%y%m%d and it works as expected. But how to add few (say 3 days) to a literal date value and how bash treats a literal value as a date. Can we say just like in ORACLE TO_DATE that my given literal date value... (2 Replies)
Discussion started by: pointers1234
2 Replies

2. Shell Programming and Scripting

Find one month before date

Hi, I want two dates one will be the current date and the other one will be just one month before. Say if current month is 11/4/2014 then the other date should be 11/3/2014. #!/bin/ksh currentDtae=`date` oneMonthBefore= ? I dont know how to do it. Went through some of the related threads... (15 Replies)
Discussion started by: Sharma331
15 Replies

3. Shell Programming and Scripting

How to find all files other than first two dates & last date per month and year?

how to find all files other than first two dates & last date per month and year Hi All, lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 a.txt -rwxr-xr-x 1 user userg 1596 Mar 19 2012 b.txt -rwxr-xr-x 1 user userg ... (6 Replies)
Discussion started by: Makarand Dodmis
6 Replies

4. UNIX for Advanced & Expert Users

Find all files other than first two files dates & last file date for month

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (16 Replies)
Discussion started by: Makarand Dodmis
16 Replies

5. Red Hat

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 (3 Replies)
Discussion started by: sunnysthakur
3 Replies

6. 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

7. 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

8. Shell Programming and Scripting

Pass the first date and last date of previous month

Hi All, I need to run a job every month at the beginning of the month which is scheduled through autosys, lets say on 03/01/2010. I need to pass the last month's i.e February's first_date = 02/01/2010 and last_date = 02/28/2010 as variables to a stored procedure. Can somebody please pass... (2 Replies)
Discussion started by: vigdmab
2 Replies

9. Shell Programming and Scripting

How to find the create time of a file if current date is in next month

Hi All, I want to find the time diffrence between currnt time and "abc.txt" file create time. I have solve that but if the abc.txt file created last month then is there any process to find the difftent? Exp: Create time of abc.txt is "Apr 14 06:48" and currect date is "May 17 23:47".... (1 Reply)
Discussion started by: priyankak
1 Replies

10. Shell Programming and Scripting

Use date command to find last month

#!/usr/bin/ksh Does anyone have a good way to set a variable to last month? For example, today is 20070810. I would like to use the date command to set a variable to last months %m code, which is 07. If I pluck this months value (08) and user expr to do simple math on it, it returns 7 (not... (5 Replies)
Discussion started by: Cbish68
5 Replies
Login or Register to Ask a Question