Get day from date variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get day from date variable
# 1  
Old 10-22-2012
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 abbreviated name of the day of week from that variable...so I start with this:
10/18/2012

and end up with this:
Thu

To be very clear about what is messing me up, I know that to do this from the system date, I can just use `date '+%A'`, but I DON'T need the day of the system date...I need the day of a date input as a parameter and stored in a variable...and no I can't use `date --date...` Please help!
# 2  
Old 10-22-2012
Quote:
Originally Posted by dbiggied
I need the day of a date input as a parameter and stored in a variable...and no I can't use `date --date...` Please help!
So whats the problem....?


Code:
date --date="$Date_var" +%A


Last edited by pamu; 10-22-2012 at 01:13 PM..
# 3  
Old 10-22-2012
This thread might help.
# 4  
Old 10-22-2012
or even with -d option Smilie
Code:
date -d "$Date_var" +"%A"

# 5  
Old 10-22-2012
Will try the link you posted, bipinajith. Was hoping for an awk or perl one-liner, but sometimes we just don't get what we want, right? Smilie


As for the other two replies, as stated in the original post, I can not use `date --date ...` I also can not use `date -d ...` I wish it was that easy, but my understanding is that these two options are GNU only, and I don't have it.
Smilie
# 6  
Old 10-22-2012
Code:
perl -e 'use POSIX qw/strftime/; @x = split /\//, $ARGV[0]; print strftime("%a", 0, 0, 0, $x[1], $x[0]-1, $x[2]-1900)' "10/22/2012"

This User Gave Thanks to balajesuri For This Post:
# 7  
Old 10-22-2012
Quote:
Originally Posted by balajesuri
Code:
perl -e 'use POSIX qw/strftime/; @x = split /\//, $ARGV[0]; print strftime("%a", 0, 0, 0, $x[1], $x[0]-1, $x[2]-1900)' "10/22/2012"

This is EXACTLY what I wanted...You are an absolute saint!
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

Day before yesterday's date

Hello All, I am writing a script in Sun Solaris I want the date for "day before yesterday", i got the yesterday's date by this command TZ=GMT+24 date +%b" "%d. Please suggest me some code to get the date for day before yesterday (6 Replies)
Discussion started by: anand2308
6 Replies

5. Shell Programming and Scripting

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" :wall: Pls help (7 Replies)
Discussion started by: novaothers
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