How to get the days of Particular date? | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

How to get the days of Particular date?

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-23-2013
Venkatesh1 Venkatesh1 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 29 October 2013, 2:19 AM EDT
Location: chennai
Posts: 62
Thanks: 6
Thanked 0 Times in 0 Posts
How to get the days of Particular date?

Quote:
Hi Am using unix Aix
I need to find out what days for a partciular date
if i give a DATE1 variable =01/01/2013

Code:
DATE1=01/01/2013

OUTPUT:
 Tue

Can anyone help me pls ..
Sponsored Links
    #2  
Old 01-23-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 22 October 2014, 8:12 PM EDT
Location: Galactic Empire
Posts: 3,387
Thanks: 235
Thanked 1,209 Times in 1,135 Posts
Refer thread
Sponsored Links
    #3  
Old 01-23-2013
Venkatesh1 Venkatesh1 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 29 October 2013, 2:19 AM EDT
Location: chennai
Posts: 62
Thanks: 6
Thanked 0 Times in 0 Posts
Thanks for reply
I have seen the thread which you have mentioned
can you please explain briefly


Code:
 
d="20120103"

day=${d#??????}
temp=${d#????}
month=${temp%??}
year=${d%????}

I wont understand what is #??? refer to ?
    #4  
Old 01-23-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 22 October 2014, 8:12 PM EDT
Location: Galactic Empire
Posts: 3,387
Thanks: 235
Thanked 1,209 Times in 1,135 Posts
These are parameter substitution that you can perform in any POSIX shell.

Here is the definition from Korn Shell manual:

Code:
${parameter#pattern}
${parameter##pattern}
                               If the shell pattern matches the beginning of
                               the value of parameter, the value of this
                               substitution is the value of the parameter
                               with the matched portion deleted; otherwise
                               the value of this parameter substituted.  In
                               the former case, the smallest matching
                               pattern is deleted; in the latter case, the
                               largest matching pattern is deleted.
${parameter%pattern}
${parameter%%pattern}
                               If the shell pattern matches the end of the
                               value of parameter, the value of parameter
                               with the matched part is deleted; otherwise
                               substitute the value of parameter.  In the
                               former, the smallest matching pattern is
                               deleted; in the latter, the largest matching
                               pattern is deleted.

So in day=${d#??????} matches 6 characters from beginning and is deleted.

I hope this helps.
Sponsored Links
    #5  
Old 02-06-2013
franzpizzo's Avatar
franzpizzo franzpizzo is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 6 February 2014, 9:56 AM EST
Posts: 68
Thanks: 0
Thanked 12 Times in 12 Posts
It might be a good alternative: return 0 for Sunday, 1 for Monday etc.

Code:
echo "(6 - $( cal $MM $YY | awk 'NR==3' |wc -w ) + ( $DD % 7 ) ) %7" | bc


Last edited by franzpizzo; 02-06-2013 at 04:36 PM..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Number of days between the current date and user defined date hiten.r.chauhan Shell Programming and Scripting 1 03-01-2011 09:13 AM
Date after 5 days from current date in YYYYMMDD format needyourhelp10 Shell Programming and Scripting 8 09-30-2010 04:33 PM
how to get what date was 28 days ago of the current system date IN UNIX kandi.reddy Shell Programming and Scripting 15 03-19-2010 12:06 AM
date for two days or 3 days ago tomjones Shell Programming and Scripting 7 06-02-2009 09:20 AM
How to find a date which is 7 days past when given current date ladtony Shell Programming and Scripting 17 04-09-2009 04:06 PM



All times are GMT -4. The time now is 01:51 AM.