To Get the day of given date in aix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To Get the day of given date in aix
# 1  
Old 01-03-2012
To Get the day of given date in aix

Hi,

Can any one help to find out the day for the given date in AIX. If we giving date as "YYYYMMDD" it should display its day.

eg:if the input is "20120103", expected output is "tuesday" Smilie

Pls help
# 2  
Old 01-03-2012
# 3  
Old 01-03-2012
You can also give this a try:
Code:
#!/bin/sh

d="20120103"

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

DOW=$(cal $month $year | awk '
BEGIN{split("Sun Mon Tue Wed Thu Fri Sat",dow);dow[0]=dow[7]}
NR==3{t=7-NF+d;print dow[t%7];exit}' d=$day)

echo $DOW

These 2 Users Gave Thanks to Franklin52 For This Post:
# 4  
Old 01-03-2012
Code:
#!/etc/edi/bin/perl -w
use Date::Manip;
use Time::Local;
my ($mt, $dt, $yr, $sec, $wk_st, $wk_nd, $st_date, $nd_date);

(@ARGV != 1) && die "Invalid parameters. Enter date in mm/dd/yyyy format. Exiting";
($ARGV[0] !~ /^(0[1-9]|1[012])\/(0[1-9]|[12][0-9]|3[01])\/[\d]{4}$/)
&& die "Invalid date format. Enter date in mm/dd/yyyy. Exiting";

$mt = substr $ARGV[0], 0, 2;
$dt = substr $ARGV[0], 3, 2;
$yr = substr $ARGV[0], 6, 4;

$sec = timelocal (0, 0, 0, $dt, $mt - 1, $yr);

$wday=localtime($sec);

print $wday;
print "\n";


---------- Post updated at 08:26 AM ---------- Previous update was at 08:25 AM ----------

modify as per your demand

Last edited by Franklin52; 01-03-2012 at 09:28 AM.. Reason: Please use code tags for code and data samples, thank you
# 5  
Old 01-03-2012
@parthmittal2007: I see that you've copy-pasted my code snippet string to string from here (post #7). With the exceptions of changing the hash-bang line and loading the Date::Manip module (which I don't see being used anywhere :-P)
# 6  
Old 01-03-2012
@balajesuri
parthmittal2007 has a lot to learn. Not just ethics.
# 7  
Old 01-04-2012
@balajesuri
Sorry if you feel hurted, my intentions are not like that. I learned from you, and giving knowledge to others.what a wrong in this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Calculate given date - 1 day

Hi Team, We have a requirement as follows. If a date 20141220 as parameter to the script, then the script has to return the output as 20141219. i.e given date - 1. The requirement is simple. But it should satisfy leap year, the months having 31 and 30 days, the date in which day light... (9 Replies)
Discussion started by: kmanivan82
9 Replies

3. AIX

Need to get the next day's date of the user entered date

I need to get the next day's date of the user entered date for example: Enter date (yyyy/mm/yy): 2013/10/08I need to get the next day's date of the user entered date Desired Output: 2013/10/09Though there are ways to achieve this is Linux or Unix environment (date command) ,I need to... (1 Reply)
Discussion started by: rpm120
1 Replies

4. Shell Programming and Scripting

Date to Day in loop

Hi All, I have a file in the following format.I need to pick up 25th field which is a date and convert it into a day and add it as a field in the file. "AAGENAS,PEARL... (3 Replies)
Discussion started by: nua7
3 Replies

5. Shell Programming and Scripting

Get day from date variable

Ok...this is really bumming me out because it seems like it should be simple, but for some reason, I just can't get it...I've also googled and searched these forums, and haven't found exactly what I'm looking for... I have a date in mm/dd/yyyy format in a variable...I need to extract the... (7 Replies)
Discussion started by: dbiggied
7 Replies

6. Shell Programming and Scripting

finding the previous day date and creating a file with date

Hi guys, I had a scenario... 1. I had to get the previous days date in yyyymmdd format 2. i had to create a file with Date inthe format yyyymmdd.txt format both are different thanks guys in advance.. (4 Replies)
Discussion started by: apple2685
4 Replies

7. UNIX for Dummies Questions & Answers

Getting date -1 day not using GNU date

It's easy as pie to get the date minus one day on opensolaris: date -d "-1 day" +"%Y%m%d"run this command on our crappy Solaris 10 machines however (which I'm guessing doesn't have GNU date running on it) and you get: date: illegal option -- d date: illegal option -- 1 date: illegal option --... (5 Replies)
Discussion started by: rich@ardz
5 Replies

8. Shell Programming and Scripting

how to obtain date and day of the week from `date` command

Hi, does anybody know how to format `date` command correctly to return the day of the week? Thanks -A I work in ksh.... (1 Reply)
Discussion started by: aoussenko
1 Replies

9. UNIX for Dummies Questions & Answers

date - 1 day

Hi, I have been trying just about every unix command to come up with yesterday's date (today's date - 1). I have seen all of the help on this forum, and none of it seems to work for me here. We are using Sun Solaris 9 Unix. I am using this script to create a .txt file with ftp commands that I will... (2 Replies)
Discussion started by: sfedak
2 Replies

10. Shell Programming and Scripting

Getting day from a date...

Hi, I have a date input in MMDDYYYY format.. I have to give the day (whether that DD is sunday/monday...) Is there any command for it... Or do I have to write a script for that... Thanks in Advance Yeheya (1 Reply)
Discussion started by: yeheyaansari
1 Replies
Login or Register to Ask a Question