DateTi...at::DBI(3pm)

πŸ“¦
version 0.041 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

DateTime::Format::DBI β€” ok so basically it finds you a parser class for a database connection. that's the whole job bestie πŸŽ€


✨ SYNOPSIS ✨

use DBI;
use DateTime;
use DateTime::Format::DBI;

my $db = DBI->connect('dbi:...');
my $db_parser = DateTime::Format::DBI->new($dbh);
my $dt = DateTime->now();

$db->do("UPDATE table SET dt=? WHERE foo='bar'",undef,
  $db_parser->format_datetime($dt);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so this module? it goes and finds a DateTime::Format::* class that actually fits the DBI connection you're using (and the DBD::* driver under it). matchmaking fr fr πŸ’…

right now it's got your back for these format modules:

  • IBM DB2 (DB2)
  • Microsoft SQL (MSSQL)
  • MySQL
  • Oracle
  • PostgreSQL (Pg)
  • SQLite
  • Sybase
NOTE: this module is a quick lil way to grab the right parser and formatter class. but that alone is usually not enough for full database abstraction, bestie 😭 you're still gonna have to deal with all the differences in syntax and semantics of SQL datetime functions (and other SQL commands too). no cap.

🌸 CLASS METHODS 🌸

this module gives you exactly one factory method, iconic behaviour:

  • new( $dbh ) β€” makes a brand new DateTime::Format::* instance. which exact class you get depends on the database driver used for the database connection that $dbh points at. surprise surprise πŸ’«

πŸŽ€ PARSER/FORMATTER INTERFACE πŸŽ€

DateTime::Format::DBI is literally just a front-end class factory β€” it hands you back one of the format classes based on the vibe of your $dbh.

want the deets on the interface of the parser object you got back? go read the documentation for the class that matches your particular $dbh, bestie 🫢

in general tho, parser classes for databases will implement these methods. for the exact behaviour of each one, check the docs of the parser class itself:

  • parse_datetime( $string ) β€” hand it a string with a date and/or time representation from your database, and it returns a fresh DateTime object ✨ if the string is improperly formatted, this method may die πŸ’€
  • format_datetime( $dt ) β€” hand it a DateTime object and it gives you back a string that works as input for all (or at least the most common) date and date/time types of your database.
  • parse_duration( $string ) β€” hand it a string with a duration representation from your database, and it returns a new DateTime::Duration object 🌈 if the string is improperly formatted, this method may die πŸ’€

not every database and format/formatter class supports durations, so please use UNIVERSAL::has to check whether this method is even available, iykyk.

  • format_duration( $du ) β€” hand it a DateTime::Duration object and it gives you back a string that works as input for the duration or interval type of your database.

again: not every database and parser/formatter class supports durations, so use UNIVERSAL::has to check that this method exists πŸ™ˆ

parser/formatter classes may additionally define methods like parse_type or format_type (where type comes from the SQL type). for more info on those, go read the documentation of the individual format class πŸ’œ


πŸ”₯ SUPPORT πŸ”₯

found bugs or got other requests? please report them to the rt tracker: <https://rt.cpan.org/Public/Dist/Display.html?Name=DateTime-Format-DBI>.


πŸ‘‘ AUTHOR πŸ‘‘

Claus Faerber <CFAERBER@cpan.org>


🌈 LICENSE 🌈

Copyright 2003-2013 Claus Faerber. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.


⭐ SEE ALSO ⭐


and that's the whole page, bestie πŸ’… this one came from perl v5.32.1, dated 2021-11-12 β€” go forth and format those datetimes, main character energy only πŸ¦‹βœ¨

πŸ“¦ where this page comes from