Pass date (YYYY-MM-DD) as parameter and get Day


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pass date (YYYY-MM-DD) as parameter and get Day
# 1  
Old 09-30-2015
Pass date (YYYY-MM-DD) as parameter and get Day

Hi,

I have a requirement where I have to pass Date to a script and get the day from it.

Ex If parameter is 2015-09-29
The output should be Tuesday.

Can you please tell me how to get that?
# 2  
Old 09-30-2015
You're a bit sparse with info about your system and what commands are available in what versions. Try
Code:
date -d"2015-09-29" +%A
Dienstag

# 3  
Old 09-30-2015
Hi,

It doesnt seem to recognize -d option. Below is the output.
Please Let me know what information you are looking for. I'll add that if that helps.
It is a SOLARIS OS with bash running on it.

Code:
date -d"2015-09-29" +%A

date: illegal option -- d
date: illegal option -- 2
date: illegal option -- 0
date: illegal option -- 1
date: illegal option -- 5
date: illegal option -- -
date: illegal option -- 0
date: illegal option -- 9
date: illegal option -- -
date: illegal option -- 2
date: illegal option -- 9
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]

# 4  
Old 09-30-2015
How about telling us your OS, shell, and date version?
# 5  
Old 09-30-2015
Hi,

Below is the information. Let me know if you need more info.

Shell is Bash.

Code:
$uname -a
SunOS sjcapp54 5.10 Generic_150400-11 sun4v sparc sun4v
 
$uname -r
5.10

$uname -m
sun4v


Last edited by ashwin3086; 09-30-2015 at 01:16 PM.. Reason: Shell info
# 6  
Old 10-01-2015
Code:
echo "2015-10-01" | perl -ne 'use POSIX qw(strftime);@y=split("-");print strftime("%A",0,0,0,$y[2],$y[1]-1,$y[0]-1900);'

This User Gave Thanks to balajesuri For This Post:
# 7  
Old 10-01-2015
Thanks balajesuri.

It works perfectly. I did go through the usage of POSIX/ strftime to understand why you have used -1 for $y[1] (Month) and was able to get the answer.

Thanks again for your help. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date format YYYY/MM/DD to DD/MM/YYYY

I am getting output of YYYY-MM-DD and want to change this to DD/MM/YYYY. When am running the query in 'Todd' to_date(column_name,'DD/MM/YYYY') am getting the required o/p of DD/MM/YYYY, But when am executing the same query(Netezza) in linux server(bash) am getting the output of YYYY-MM-DD file... (3 Replies)
Discussion started by: Roozo
3 Replies

2. UNIX for Dummies Questions & Answers

Epoch date to YYYY/MM/DD or MM/DD/YYYY

I've seen a lot of posts on this and have tried the following: echo 1257000000| perl -e '($d,$m,$y)=(localtime(time-86400));$m+=1;$y+=1900;printf "$y/$m/$d\n";' But I am unable to convert a past Epoch date into a format such as YYYY/MM/DD or MM/DD/YYYY. I am using bash and don't know... (4 Replies)
Discussion started by: newbie2010
4 Replies

3. Shell Programming and Scripting

Date conversion help from dd/mm/yyyy to dd/Mon/yyyy i.e. 28/10/2012 to 28/Oct/2012

Hi I have a problem with Date format in my code. 1st I am trying to convert today's date to yesterday's using YESTERDAY3=`perl -e '@y=localtime(time()-86400); printf "%04d/%02d/%02d",$y+1900,$y+1,$y;$y;'` And once it is done I am trying to using the yesterday date in a grep command to... (3 Replies)
Discussion started by: nithinankam
3 Replies

4. Shell Programming and Scripting

Day of year to dd.mm.yyyy format

Hi, How can I convert day of year value in format(yy,doy) to normal formatted (dd.mm.yyyy) string also all of them with awk or awk system function? in_file.txt --------- 12,043 12,044 12,045 12,046 out_file.txt ---------- 12.02.2012 13.02.2012 14.02.2012 15.02.2012 imagine... (5 Replies)
Discussion started by: kocaturk
5 Replies

5. Shell Programming and Scripting

Converting date DD MM YYYY to DD MON YYYY

Hello, I am writing a script that parses different logs and produces one. In the source files, the date is in DD MM YYYY HH24:MI:SS format. In the output, it should be in DD MON YYY HH24:MI:SS (ie 25 Jan 2010 16:10:10) To extract the dates, I am using shell substrings, i.e.: read line ... (4 Replies)
Discussion started by: Adamm
4 Replies

6. Shell Programming and Scripting

get system date, format it, pass it as a parameter to a perl script - all in cron job

I am trying to get the string containing date - in a specfic format actually, although I think that part is inconsequencial - 1110226^1110226^1110226^1110226^1110226 - through echo or printf or in some other way - created within a cront job and passed as a parameter to a perl script. Now, I know... (3 Replies)
Discussion started by: v8625
3 Replies

7. Shell Programming and Scripting

change date format from yyyy/mm/dd to dd/mm/yyyy

(Attention: Green PHP newbie !) I have an online inquiry form, delivering a date in the form yyyy/mm/dd to my feedback form. If the content passes several checks, the form sends an e-mail to me. All works fine. I just would like to receive the date in the form dd/mm/yyyy. I tried with some code,... (6 Replies)
Discussion started by: keyboarder
6 Replies

8. Shell Programming and Scripting

Function to get day of week from YYYY-MM-DD date

Can't find out how to get the day of the week from a given date, anyone got a code snippet that could help please? Ta!! (4 Replies)
Discussion started by: couponmeup
4 Replies

9. Shell Programming and Scripting

converting the date field from dd/mm/yyyy to yyyy/mm/dd

How to convert the date field from dd/mm/yyyy to yyyy/mm/dd in unix my script will generate text file which have two fields one is date and another is name of the server for example this is sample date which I have to sort based on older to newer date the problem is when I found out sort will... (4 Replies)
Discussion started by: pareshan
4 Replies

10. Shell Programming and Scripting

Change Date from dd-mmm-yyyy to mm/dd/yyyy

I want to change a date from format dd-mmm-yyyy to mm/dd/yyyy. Is there a way to do this with sed or do you have to write a case statement to convert JAN to 01? Thanks (9 Replies)
Discussion started by: stringzz
9 Replies
Login or Register to Ask a Question