UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 30th, 2006, 05:58 AM
nevil_m nevil_m is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 68 nevil_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 49 m 24 sec
Reputation Power: 4
Tomorrow's date

What syntax is used to get tomorrows date. I am using HP unix ver 11.0

Reply With Quote
  #2  
Old November 30th, 2006, 08:03 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Novice (500 - 999 posts) Click here for more information
 
Join Date: Mar 2006
Posts: 930 SimonJM User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)SimonJM User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)SimonJM User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)SimonJM User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)SimonJM User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)SimonJM User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)SimonJM User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)SimonJM User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)SimonJM User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)SimonJM User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)SimonJM User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 2 Weeks 6 Days 5 h 48 m 41 sec
Reputation Power: 499
Are you just using shell scripting? And what aprt of the date are you after - dd/mm/yy or day name, etc.?

Reply With Quote
  #3  
Old November 30th, 2006, 08:17 AM
suresh_kumarmp's Avatar
suresh_kumarmp suresh_kumarmp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 45 suresh_kumarmp User rank is Corporal (100 - 500 Reputation Level)suresh_kumarmp User rank is Corporal (100 - 500 Reputation Level)suresh_kumarmp User rank is Corporal (100 - 500 Reputation Level)suresh_kumarmp User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 15 h 52 m 38 sec
Reputation Power: 8
Try to use "calendar - reminder service"

I am not pretty sure :-)

Suresh
__________________
Add to my reputation if it really helped

Reply With Quote
  #4  
Old November 30th, 2006, 08:41 AM
mu's Avatar
mu mu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Location: Dublin, Ireland
Posts: 174 mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 39 m 56 sec
Reputation Power: 39
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
$

Reply With Quote
  #5  
Old November 30th, 2006, 02:08 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,319 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 11 h 12 m
Reputation Power: 49
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.

Reply With Quote
  #6  
Old November 30th, 2006, 11:09 PM
nevil_m nevil_m is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 68 nevil_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 49 m 24 sec
Reputation Power: 4
Quote:
Originally Posted by SimonJM
Are you just using shell scripting? And what aprt of the date are you after - dd/mm/yy or day name, etc.?


Yes using shell scripting. Format requuired id dd/mm/yyyy

Reply With Quote
  #7  
Old November 30th, 2006, 11:30 PM
nevil_m nevil_m is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 68 nevil_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 49 m 24 sec
Reputation Power: 4
Quote:
Originally Posted by iota
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
$


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.

Reply With Quote
  #8  
Old November 30th, 2006, 11:35 PM
nevil_m nevil_m is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 68 nevil_m User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 49 m 24 sec
Reputation Power: 4
It did help

Quote:
Originally Posted by jim mcnamara
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.


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 ?

Reply With Quote
  #9  
Old December 1st, 2006, 07:47 AM
mu's Avatar
mu mu is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Location: Dublin, Ireland
Posts: 174 mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level)mu User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 23 h 39 m 56 sec
Reputation Power: 39
Quote:
Originally Posted by nevil_m
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.


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.

Reply With Quote
  #10  
Old December 1st, 2006, 09:40 AM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,319 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 11 h 12 m
Reputation Power: 49
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Tomorrow's date


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT