Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

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 May 31st, 2000, 05:46 PM
bydavid bydavid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: USA
Posts: 67 bydavid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
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

Reply With Quote
  #2  
Old June 1st, 2000, 12:57 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

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..."

Reply With Quote
  #3  
Old June 2nd, 2000, 08:54 PM
pschon pschon is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 16 pschon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
<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;
}



Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > getting the date to insert into mySQL

Developer Shed Advertisers and Affiliates



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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap