|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Tomorrow's date
What syntax is used to get tomorrows date. I am using HP unix ver 11.0
|
|
#2
|
|||
|
|||
|
Are you just using shell scripting? And what aprt of the date are you after - dd/mm/yy or day name, etc.?
|
|
#3
|
||||
|
||||
|
Try to use "calendar - reminder service"
I am not pretty sure :-) Suresh
__________________
Add to my reputation if it really helped
|
|
#4
|
||||
|
||||
|
You could install the GNU-coreutils on HP and use the date command with the --tomorrow switch or something to that effect.
Personally though I'd write a small program to do the job. Code:
#include <time.h>
#include <stdio.h>
#define SECOND 60
#define MINUTE 60
#define HOUR 24
int main(int argc, char ** argv) {
time_t today = time(NULL);
time_t tomorrow = today + (time_t)(HOUR * MINUTE * SECOND);
struct tm tim = *(localtime(&tomorrow));
char date_tomorrow[100];
strftime(date_tomorrow, 100, argv[1], &tim);
printf("%s\n", date_tomorrow);
}
Save as date.c and compile with: Code:
gcc date.c -o d Code:
$ ./d Fri Dec 01 14:35:05 2006 $ ./d '%Y-%m-%d %H:%M:%S' 2006-12-01 14:35:06 # as a constrast $ date Thursday November 30 14:35:08 GMT 2006 $ date '+%Y-%m-%d %H:%M:%S' 2006-11-30 14:35:15 $ |
|
#5
|
|||
|
|||
|
Code:
#!/bin/ksh
tomorrow()
{
perl -e '
# today plus 86400 seconds is this time tomorrow
$tomorrow = time + 86400;
# this line gets the month name
$month = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[(localtime $yesterday)[4]];
# day of the month
$day = (localtime $tomorrow)[3];
$yr= (localtime $tomorrow)[5] + 1900;
print "$month $day $yr", "\n";
'
}
echo "Day after today is $( tomorrow )"
One way is to use a perl (or some other similarly-featured interpreted language like python) and create a small subroutine. I picked perl because most unix boxes have it. |
|
#6
|
|||
|
|||
|
Quote:
Yes using shell scripting. Format requuired id dd/mm/yyyy |
|
#7
|
|||
|
|||
|
Quote:
I get an error while compiling as (Bundled) cc: "date.c", line 8: error 1705: Function prototypes are an ANSI feature. (Bundled) cc: "date.c", line 11: error 1716: Automatic aggregate initialization is an ANSI feature. |
|
#8
|
|||
|
|||
|
It did help
Quote:
It did work. But month is appearing as Jan. Even the month is incrementing by 1. Can we get o/p in dd/mm/yyyy format ? |
|
#9
|
||||
|
||||
|
Quote:
Hmm.. From what I've been reading on Google, HP's bundled compiler isn't ANSI compliant and is only used for compiling kernels. You'll need to use GCC or HP's ANSI C. |
|
#10
|
|||
|
|||
|
The default HP compiler is basically K&R. It's marketing ploy to get you to buy a modern compiler...
Code:
#!/bin/ksh
tomorrow()
{
perl -e '
# today plus 86400 seconds is this time tomorrow
$tomorrow = time + 86400;
# this line gets the month name
$month = (localtime $tomorrow)[4];
$month = (++$month < 10) ? "0$month" : "$month";
# day of the month
$day = (localtime $tomorrow)[3];
$day = ($day < 10) ? "0$day" : "$day";
$yr= (localtime $tomorrow)[5] + 1900;
printf "%s/%s/%s\n", $month, $day, $yr;
'
}
echo "Day after today is $( tomorrow )"
This outputs 12/02/2006 on December 1, 2006 |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Tomorrow's date |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|