Date in Solaris


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date in Solaris
# 1  
Old 12-02-2009
Date in Solaris

Hi,

I am working on date operations in perl. using following code, I am getting today date as per my required format.

Code:
my $date1 = `date '+%m/%d/%Y'`;

can I find day+1 date. (ie. If today is 12/01/2009 then I want to edit above code t find 12/02/2009)

---------- Post updated 12-02-09 at 01:58 AM ---------- Previous update was 12-01-09 at 08:28 PM ----------

can anyone please advice
gentleDean
# 2  
Old 12-02-2009
Why do you call an external program for something that Perl can do fine by itself?
Code:
$ cat time.pl
#!/usr/bin/perl

use strict;
use warnings;

my $time     = time;
my @today    = localtime($time);
my @tomorrow = localtime( $time + 24 * 60 * 60 );

printf "   Today: %02d/%02d/%04d\n", $today[4] + 1, $today[3], $today[5] + 1900;
printf "Tommorow: %02d/%02d/%04d\n", $tomorrow[4] + 1, $tomorrow[3],
  $tomorrow[5] + 1900;
$ perl time.pl
   Today: 12/02/2009
Tommorow: 12/03/2009

See the Perl documentation for time, localtime, and gmtime for more information.

Last edited by pludi; 12-02-2009 at 06:36 AM.. Reason: corrected code
# 3  
Old 12-02-2009
Will it give me 12/01/2009 after 11/30/2009. It shouldnt be 11/31/2009.

Also how to take it in a variable?

Last edited by gentleDean; 12-02-2009 at 05:30 AM.. Reason: Asked one more question
gentleDean
# 4  
Old 12-02-2009
  1. Try it. In the above example, change the line
    Code:
    my $time     = time;

    to
    Code:
    my $time     = 1259578800; # 2009-11-30 12:00:00 PM

    and run it again.
  2. perldoc -f sprintf
We won't do all the work for you, you know.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Solaris Date format help please

I have list of dates in a file. Am reading each line and trying to format date, Can you please help me ? Sample file content: 02/22/16 USA is great country 02/21/16 USA future 02/23/16 who is he I want to read each line from above file and format date as below 2016-02-21 (i.e., using... (1 Reply)
Discussion started by: prince1987
1 Replies

2. UNIX for Dummies Questions & Answers

Solaris Date in different language

For some reason when I do a date command I get response in another language: maandag 15 augustus 2011 15.13 u. EDT /etc/default/init file has this: TZ=US/Eastern CMASK=022 How do I change locale to English? This is Solaris 10 x86 (3 Replies)
Discussion started by: bratan
3 Replies

3. Solaris

Solaris container date diference

Hi people, I dont have a real problem, its also a so strange issue. When i connect to my system from a ssh session or telnet normaly from putty and execute the command "date" its show me the correctly time in BRT format for root and all other users. But when i connect from the global... (3 Replies)
Discussion started by: anonymouzz
3 Replies

4. Solaris

Yesterday's date on Sun solaris

Can someone help me with the command to get yesterday's date on Sun solaris?? (1 Reply)
Discussion started by: sachinkl
1 Replies

5. Solaris

Change date format in solaris 10

Hi We have upgraded our sun machine from solaris 9 to solaris 10. Before upgradation the date command output(Solaris 9) Wed Oct 13 09:45:21 IST 2010 But after upgradation the output for date is as below(solaris 10). Wednesday, October 13, 2010 9:46:14 AM IST Looks like I need to... (1 Reply)
Discussion started by: csreenivas
1 Replies

6. Solaris

Creation Date of Solaris User

Hi, I am using Solaris 10. How could I find when a solaris user was created? thanks and regards (4 Replies)
Discussion started by: fahdmirza
4 Replies

7. Solaris

date -d illegal option in Solaris

Hi All, Is it possible to run date -d option in Solaris? Do we have a work around so that -d option will be recognized by solaris as it is recognized by linux. I need this since i am using this in scripting and it works in Linux box. my problem is it doesn't work in solaris box. ... (6 Replies)
Discussion started by: linuxgeek
6 Replies

8. Shell Programming and Scripting

date -d compatibility on Solaris

Hello there ppl, I thought my question would qualify to be posted in this forum and in Solaris forum. And I swear to God.. there is no discussion on this exact topic anywhere else on the web! So my script on BASH uses 2 commands: 1) date -d "Fri Mar 06 10:18:16 UTC 2009" +%s This... (3 Replies)
Discussion started by: pavanlimo
3 Replies

9. Solaris

date -d nightmare on Solaris

Hello there ppl, I thought my question would qualify to be posted in this forum and in Shell scripting forum. And I swear to God.. there is no discussion on this exact topic anywhere else on the web! So my script on BASH uses 2 commands: 1) date -d "Fri Mar 06 10:18:16 UTC 2009" +%s ... (1 Reply)
Discussion started by: pavanlimo
1 Replies

10. UNIX for Dummies Questions & Answers

Install Date of Solaris Machine

Hello: Could some one tell me how to find out the install date (creation time) of the system? Solaris 8. Thanks. (2 Replies)
Discussion started by: smoothstylez
2 Replies
Login or Register to Ask a Question