Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
when i execute the above code i got the below output:
Output: 20130715
How can i display the same output in 15/07/2013, i tried with the format '+%d/%m/%y'` but i am getting error.
also how can i get the first day of the month based on the date which is fetched $yest=20130715.
for example: 01/07/2013 which is first day on the monthe
Any help.
Thanks
OK, this is Dirty..
Code:
#!/usr/bin/ksh
function Yest {
Year=$1
Month=$2
Day=$3
YDay=$(expr $Day - 1)
date '+%A %d/%m/%Y' --date=${Year}-${Month}-${Day}
date '+%A %d/%m/%Y' --date=${Year}-${Month}-${YDay}
date '+%A %d/%m/%Y' --date=${Year}-${Month}-01
}
Yest $(date '+%Y %m %d')
passing 3 arguments to a function
The arguments are the output of date formatted such that we have spaces between year month and day
this is so we can easily manipulate the day ( to get yesterday )
Hope that makes sense
Last edited by Firerat; 07-16-2013 at 12:16 AM.
Reason: added day of week to justfy using date instead of just echo/printf
If you're just concerned about printng the first date of given months in ddmmyyyy format according to provided date as input, then it can be done simply as:
Code:
#!/bin/bash
echo "Insert date: "; read mydate ## Here you have to provide date format e.g. 15072013 as your input
month=$(echo $mydate| cut -c 3-4)
year=$(echo $mydate | cut -c 5-8)
echo 01$month$year
The question is i am trying to fetch the previous day using current date. for example if current date is 16/07/2013, i want previous day's date. i.e., 15/07/2013.
using current date fetch yesterday's date.
Input current date and output is current date - 1 - 15/07/2013.
The question is i am trying to fetch the previous day using current date. for example if current date is 16/07/2013, i want previous day's date. i.e., 15/07/2013.
using current date fetch yesterday's date.
Input current date and output is current date - 1 - 15/07/2013.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.