Similar Threads:
1.Translate standard date/time format to EPOCH seconds
Good morning All.
I am looking for a way to translate date/timestamps in various formats to EPOCH seconds without using a module (cannot use a module in this situation other then the standard modules installed with Perl).
I am going to create a subroutine and parse the date/timestamp passed into it's various components. I will then pass those components to the timelocal function to return the EPOCH seconds.
Ex:
$dayOfWeek, $day, $month, $hour, $min, $sec, $year=split /\s+|:/, $_[0];
my %months=qw(Jan 0 Feb 1 Mar 2 Apr 3 May 4 Jun 5 Jul 6 Aug 7 Sep 8 Oct 9 Nov 10 Dec 11);
$month=$months{$month};
$time=timelocal($sec,$min,$hour,$day,$month,$year);
The problem is, the date/timestamp passed can be of various formats:
Ex:
Tuesday, 04/26/2005 06:02:43 PM
Tuesday, 26/04/2005 18:02:43
04/26/2005 06:02:43 PM
26/04/2005 06:02:43 PM
04/26/2005 18:02:43
etc..
I am looking for a way to gracefully handle the format using a format parameter passed with the date/timstamp to the subroutine.
Ex. my $epoch=convert_to_epoch("Tuesday, 26/04/2005 18:02:43","Day, DD/MM/YYYY HH24:MM:SS")
my $epoch=convert_to_epoch("04/26/2005 06:02:43 PM" ,"DD/MM/YYY HH12:MM:SS")
Is there a gracefull way of doing this WITHOUT using if if/elsif loop to parse every possible format type?
Again, I cannot use a module in this situation due to limitations of the runtime environment.
Thanks!
Jason
2.howto Date Time string from MYSQL to German Format
I want to format DateTime string which looks like "2007-10-12
14:00:00" to German Format like "Montag, den 12. Oktober 2007"
This code (1) does not work:
$german_date = ParseDate('2007-10-12 14:00:00');
printf ("Minverbraucht : %s\n",Date_to_Text_Long($german_date));
this code (2) works, because @anliefertag is already formatted as
DateTime:
printf ("Anliefertag : %s\n",Date_to_Text_Long(@anliefertag))
any solutions from you how to format dateTime in example (1)?
tnx in advance
thomas
3.Can I set date format / style on DBI ADO connection
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Hi,
I am using DBI ADO connection to access MS SQL Server. I switched from ODBC to ADO recently.
ADO connection is returning the date format as mm/dd/yy hh:mi:ss, where as ODBC connection returns datetime in yyyy-mm-dd hh:mi:ss(24hr) format.
A lot of code is built to handle the dates returned from queries in ODBC canonical format.
I can change all the queries using CONVERT function to return in ODBC canonical format, instead of doing that for all queries, is there anyway I can specify a date time format / style for ADO Connection, so that all the dates returned by queries will be in the format specified.
Thanks,
Kumar Talinki
4.Date Format for INFORMIX using DBI
Hi,
I am using the DBI to extract some data from the underlying Informix
Database. Even after doing the following when I am printing the value
for $start_date, it is in the format 'dd/mm/yyyy' instead of the
expected 'yyyy/mm/dd'. Can any of you advise as to why this is
happening..??
$sth = $dbh->prepare("select company,customer, pur_order, ref,
start_date, end_date, limit, on_billing, page_break, cons_usage,
cons_items, memo, pref_date, first_bill, igpm_adv,comment1, comment2,
comment3 from purchase_order");
($rv = $sth->execute);
$sth->bind_col(5, \$start_date, { TYPE => DBI::SQL_DATE });
while (($company,$customer, $pur_order, $ref,$limit, $on_billing,
$page_break, $cons_usage, $cons_items, $memo, $first_bill,
$igpm_adv,$comment1, $comment2, $comment3 ) = $sth->fetchrow)
{
print "\nStart Date is : ${start_date}\n" ;
}
Regards
Nitin Nair
5.DBI, MS Access, inserting/updating a Access Date/Time value
Hi,
Does anyone have any idea what is up with Microsoft Access and its
ridiculous Date/Time formatting options? It doesn't seem to matter what
format I attempt to insert with. The directory and db file permissions
are all Full Control. I'm using the "#" around the Date/Time format as
required. The database has nothing as the Format in Design view on the
General tab. The insert below has never worked once. On the up side if I
run an insert that has no mention of the Date/Time field then it will
just insert the record using the =Now() function as the default value
but that doesn't help much considering I would want to update the field.
There are no question marks in any of the field names as suggested on
many pages dicussing this error below. Thanks for any help! I'm using
MS Access, Perl, DBI & DBD::ODBC win32 modules, IIS on XP.
Here is the error:
.......................................................................
DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access
Driver]COUNT field incorrect (SQL-07002)(DBD: st_execute/SQLExecute
err=-1) at C:\Inetpub\Scripts\somedir\dsntest.pl line 18.
.......................................................................
Here is the code:
.......................................................................
#!C:\perl\bin\perl.exe
#
#print "Content-type: text/html\n\n";
use DBI;
# 2005-04-12 20:48:31
# 4/5/2004 5:3:45 PM
# 4/12/2005 10:28:14 PM
# d m yyyy h:m:s AM/PM
$dt = "#4/5/2004 5:3:45 PM#";
$sql = "INSERT INTO tblTest (TimeStamp) VALUES ($dt)";
my $dbh = DBI->connect("dbi:ODBC:dsntest", "", "", { PrintError => 0,
RaiseError => 1 })
|| die "database connection can't connect to database
$DBI::errstr";
my $sth = $dbh->prepare($sql) || die "prepare statement- $DBI::errstr";
$sth->execute() || die "execute statement- $DBI::errstr";
$sth->finish;
.......................................................................
6. Help w/Class::Date Date.xs
7. Date::Calc and postgres timestamp
8. Class::DBI vs DBIx::Class