Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current Month

Status
Not open for further replies.

TyzA

Programmer
Jan 7, 2002
86
BE
Hi,

How can I retrieve the current month with MySQL in a PERL cgi script.

I've tried something like "select to_char(sysdate,'Month') from dual", but this doesn't work.

Is t possible that you can't perform date functions, or any other fuction in MySQL.

Thanks for your help,

Tijs Programming is like sex: one mistake and you have to support it for the rest of your life.
 
read this thread219-283250 ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
from : Example #1:

You have performed all your time/date operations using gmtime() and timegm() and now have your date/time represented as SECONDS stored in $TimeInSeconds and you want to display this time in the Europe/Paris time zone.

use Time::Local;
my @dayofweek = (qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday));
my @monthnames = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday);
$ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime($TimeInSeconds);
$year += 1900;
print "This date is $dayofweek[$wday], $monthnames[$mon] $mday, $year\n";
print "This time is $hour:$min:$sec\n";

Example #2:

You have performed all your time/date operations using gmtime() and timegm() and now have your date/time represented as a UTC broken-down time stored in the variables $sec, $min, etc., and you want to display this time in the Europe/Paris time zone.

use Time::Local;
my $TimeInSeconds;
#convert from UTC to Europe/Paris
$ENV{TZ} = ':/usr/share/zoneinfo/Europe/Paris';
#convert broken-down time to seconds in UTC
$TimeInSeconds = timegm($sec,$min,$hour,$mday,$mon,$year,$wday,$yday);
#convert the UTC seconds to broken-down time in time zone
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime($TimeInSeconds); ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
You can get the current local month w/o using the db server like this.....

Code:
#!/usr/local/bin/perl
$month = (1..12)[(localtime)[4]];
print "month number - $month\n";

$month = ('jan','feb','mar','apr',
    'may','jun','jul','aug','sep',
    'oct','nov','dec')[(localtime)[4]];
print "month abbreviation - $month\n";

as always, tmtowtdi ;-) 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Thanks guys,

It's working fine now. Programming is like sex: one mistake and you have to support it for the rest of your life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top