12-18-2008
Let's say your in Central Time zone.
Your timezone might be represented by
TZ=CST6CDT
You could get the prior day by doing
TZ=CST30CDT
(6 + 24 = 30)
So:
$ TZ=CST30CDT date +%B
Should give you yesterday.
Alternatively you can install GNU's date program which can do date arithmetic.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
How to find the first day of previous month in unix mmddyyyy format?
example : today is 07052007 (in mmddyyyy)
output sud be 06012007
thanks
mohapatra (10 Replies)
Discussion started by: mohapatra
10 Replies
2. Shell Programming and Scripting
Hi,
I want a script(ksh) to see if today is the last working day(Mon-Fri) of the month. If it is the last working day I need to print current date, else I need the last working day of previous month. Thanks in advance. (1 Reply)
Discussion started by: rspk_praveen
1 Replies
3. Shell Programming and Scripting
Hi, I'm new with Unix, I'm trying to get a last day of previous month with this format: %b %d %Y (example: Feb 25 2008).
Here is what I have so far.
#!/bin/ksh
cur_month=`date +%m`
cur_year=`date +%Y`
prev_month=$(($cur_month-1))
# Check to see if this is January
if
then
... (11 Replies)
Discussion started by: sirrtuan
11 Replies
4. Shell Programming and Scripting
Hello - I have one question regarding the date. I wanted to display the month name for previous day. The output should be as follows...
5-Feb-09 => February
1-Feb-09 => January
28-Feb-09=> February
Here is the code i am using to get the output....
date '+%m %d %Y' |
{
read MONTH DAY... (4 Replies)
Discussion started by: govindts
4 Replies
5. UNIX for Dummies Questions & Answers
Hello,
I'm new to shell scripting.
We've develop a script which will grep a file on the search criteria, MON (Jan/Feb/Mar/etc). But we should set this sript in cron which will run on every first day of the month. The problem I'm having is, when I run the script, it is displaying the contents of... (7 Replies)
Discussion started by: suneelj
7 Replies
6. Shell Programming and Scripting
Hi All,
I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this.
My Requirment is as below:
Input for me will be 2000909(YYYYMM)
I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies
7. UNIX for Dummies Questions & Answers
Hi folks
month=`date +%m`gives current month
Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies
8. Programming
Hi Guys,
How to get First day of previous month and last day of previous month from trunc(sysdate) using SQL..?
Thanks in advance.
Br,
pinpe (2 Replies)
Discussion started by: pinpe
2 Replies
9. UNIX for Dummies Questions & Answers
Hi All,
I am using the below code to get the year and month from date:
Below gives output like 201212.
dt=`date '+%Y%m'`
how do i get the previous month value(ie: subtract 1 from date)
example output:
dt=201211
Please help. :confused: (3 Replies)
Discussion started by: abhi_123
3 Replies
10. Shell Programming and Scripting
I have requirment to get last date of previous month and the first date of previous 4th month:
Example:
Current date: 20130320 (yyyymmdd)
Last date of previous month: 20130228 (yyyymmdd)
First date of previous 4th month: 20121101 (yyyymmdd)
In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies
GETDATE(3) 1 GETDATE(3)
getdate - Get date/time information
SYNOPSIS
array getdate ([int $timestamp = time()])
DESCRIPTION
Returns an associative array containing the date information of the $timestamp, or the current local time if no $timestamp is given.
PARAMETERS
o $timestamp
- The optional $timestamp parameter is an integer Unix timestamp that defaults to the current local time if a $timestamp is not
given. In other words, it defaults to the value of time(3).
RETURN VALUES
Returns an associative array of information related to the $timestamp. Elements from the returned associative array are as follows:
Key elements of the returned associative array
+----------+--------------------------------------+---+
| Key | | |
| | | |
| | Description | |
| | | |
| | Example returned values | |
| | | |
+----------+--------------------------------------+---+
| | | |
|"seconds" | | |
| | | |
| | Numeric representation of seconds | |
| | | |
| | | |
| | 0 to 59 | |
| | | |
| | | |
|"minutes" | | |
| | | |
| | Numeric representation of minutes | |
| | | |
| | | |
| | 0 to 59 | |
| | | |
| | | |
| "hours" | | |
| | | |
| | Numeric representation of hours | |
| | | |
| | | |
| | 0 to 23 | |
| | | |
| | | |
| "mday" | | |
| | | |
| | Numeric representation of the day of | |
| | the month | |
| | | |
| | | |
| | 1 to 31 | |
| | | |
| | | |
| "wday" | | |
| | | |
| | Numeric representation of the day of | |
| | the week | |
| | | |
| | | |
| | 0 (for Sunday) through 6 (for Satur- | |
| | day) | |
| | | |
| | | |
| "mon" | | |
| | | |
| | Numeric representation of a month | |
| | | |
| | | |
| | 1 through 12 | |
| | | |
| | | |
| "year" | | |
| | | |
| | A full numeric representation of a | |
| | year, 4 digits | |
| | | |
| | Examples: 1999 or 2003 | |
| | | |
| | | |
| "yday" | | |
| | | |
| | Numeric representation of the day of | |
| | the year | |
| | | |
| | | |
| | 0 through 365 | |
| | | |
| | | |
|"weekday" | | |
| | | |
| | A full textual representation of the | |
| | day of the week | |
| | | |
| | | |
| | Sunday through Saturday | |
| | | |
| | | |
| "month" | | |
| | | |
| | A full textual representation of a | |
| | month, such as January or March | |
| | | |
| | | |
| | January through December | |
| | | |
| | | |
| 0 | | |
| | | |
| | Seconds since the Unix Epoch, simi- | |
| | lar to the values returned by | |
| | time(3) and used by date(3). | |
| | | |
| | System Dependent, typically | |
| | -2147483648 through 2147483647. | |
| | | |
+----------+--------------------------------------+---+
EXAMPLES
Example #1
getdate(3) example
<?php
$today = getdate();
print_r($today);
?>
The above example will output something similar to:
Array
(
[seconds] => 40
[minutes] => 58
[hours] => 21
[mday] => 17
[wday] => 2
[mon] => 6
[year] => 2003
[yday] => 167
[weekday] => Tuesday
[month] => June
[0] => 1055901520
)
SEE ALSO
date(3), idate(3), localtime(3), time(3), setlocale(3).
PHP Documentation Group GETDATE(3)