1Time::Piece::MySQL(3) User Contributed Perl DocumentationTime::Piece::MySQL(3)
2
3
4
6 Time::Piece::MySQL - Adds MySQL-specific methods to Time::Piece
7
9 use Time::Piece::MySQL;
10
11 my $time = localtime;
12
13 print $time->mysql_datetime;
14 print $time->mysql_date;
15 print $time->mysql_time;
16
17 my $time = Time::Piece->from_mysql_datetime( $mysql_datetime );
18 my $time = Time::Piece->from_mysql_date( $mysql_date );
19 my $time = Time::Piece->from_mysql_timestamp( $mysql_timestamp );
20
22 Using this module instead of, or in addition to, "Time::Piece" adds a
23 few MySQL-specific date-time methods to "Time::Piece" objects.
24
26 mysql_date / mysql_time / mysql_datetime / mysql_timestamp
27 Returns the date and/or time in a format suitable for use by MySQL.
28
30 from_mysql_date / from_mysql_datetime / from_mysql_timestamp
31 Given a date, datetime, or timestamp value as returned from MySQL,
32 these constructors return a new Time::Piece object. If the value is
33 NULL, they will retrun undef.
34
35 CAVEAT
36 "Time::Piece" itself only works with times in the Unix epoch, this
37 module has the same limitation. However, MySQL itself handles date and
38 datetime columns from '1000-01-01' to '9999-12-31'. Feeding in times
39 outside of the Unix epoch to any of the constructors has unpredictable
40 results.
41
42 Also, MySQL doesn't validate dates (because your application should);
43 it only checks that dates are in the right format. So, your database
44 might include dates like 2004-00-00 or 2001-02-31. Passing invalid
45 dates to any of the constructors is a bad idea: on my system the former
46 type (with zeros) returns undef (previous version used to die) while
47 the latter returns a date in the following month.
48
50 Original author: Dave Rolsky <autarch@urth.org>
51
52 Current maintainer: Marty Pauley <marty+perl@kasei.com>
53
55 (c) 2002 Dave Rolsky
56
57 (c) 2004 Marty Pauley
58
59 This program is free software; you can redistribute it and/or modify it
60 under the same terms as Perl itself.
61
63 Time::Piece
64
65
66
67perl v5.36.0 2023-01-20 Time::Piece::MySQL(3)