|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
hello
i am trying to make a log table where i insert the date into the table. how can i grab the current date in a yyyy-mm-dd format? thanks for the help |
|
#2
|
||||
|
||||
|
Hi David, you can use this following script for getting the date in yyyy-mm-dd format. just use &date_format for passing this date format to the database. #!/usr/bin/perl ####-----Create yyyy-mm-dd date format---#### print &date_format; sub date_format{ ($sec,$min,$hour,$wday,$month,$year,$mday)=localtime(time()); $month="0".$month if ($month)<10; #make month in 2 digits if it is less than 2 $wday="0".$wday if ($wday)<10; #make date in 2 digits if it is less than 2 $yr=substr($year,1); $yr="20".$yr if length($yr)==2; #make year in 4 digits $date=$yr."-".$month."-".$wday; #concatenate the date in yyyy-mm-dd format. return $date; } ------------------ SR - shiju.dreamcenter.net "The fear of the LORD is the beginning of knowledge..." |
|
#3
|
|||
|
|||
|
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by bydavid:
hello i am trying to make a log table where i insert the date into the table. how can i grab the current date in a yyyy-mm-dd format? [/quote] I'm a lazy guy so I use modules. Here is an interesting way: use strict; use Date::Calc qw(Today Add_Delta_Days); print mysql_date(-1); print mysql_date(); print mysql_date(+1); print mysql_date(+2); sub mysql_date { my $offset = shift | | 0; my @today = Today(); my @date = Add_Delta_Days(@today,$offset); my $year = sprintf("%4d", $date[0]); my $month = sprintf("%02d", $date[1]); my $day = sprintf("%02d", $date[2]); my $mysql_date = qq|$year-$month-$dayn|; return $mysql_date; } |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > getting the date to insert into mySQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|