# phpman > perldoc > Data::FormValidator::Constraints::Dates

## NAME
    [Data::FormValidator::Constraints::Dates](https://www.chedong.com/phpMan.php/perldoc/Data%3A%3AFormValidator%3A%3AConstraints%3A%3ADates/markdown) - Validate Dates and Times

## SYNOPSIS
        use [Data::FormValidator::Constraints::Dates](https://www.chedong.com/phpMan.php/perldoc/Data%3A%3AFormValidator%3A%3AConstraints%3A%3ADates/markdown) qw(date_and_time);

        # In a DFV profile...
        constraint_methods => {
            # 'pp' denotes AM|PM for 12 hour representation
            my_time_field => date_and_time('MM/DD/YYYY hh:mm:ss pp'),
        }

## DESCRIPTION
  date_and_time
    Note: This is a new module is a new addition to [Data::FormValidator](https://www.chedong.com/phpMan.php/perldoc/Data%3A%3AFormValidator/markdown) and is should be considered
    "Beta".

    This constraint creates a regular expression based on the format string passed in to validate
    your date against. It understands the following symbols:

        Y   year  (numeric)
        M   month (numeric)
        D   day   (numeric)
        h   hour
        m   minute
        s   second
        p   AM|PM

    Other parts of the string become part of the regular expression, so you can do perlish things
    like this to create more complex expressions:

        'MM?/DD?/YYYY|YYYY-MM?-DD?'

    Internally [Date::Calc](https://www.chedong.com/phpMan.php/perldoc/Date%3A%3ACalc/markdown) is used to test the functions.

## BACKWARDS COMPATIBILITY
    This older, more awkward interface is supported:

        # In a [Data::FormValidator](https://www.chedong.com/phpMan.php/perldoc/Data%3A%3AFormValidator/markdown) Profile:
        validator_packages => [qw([Data::FormValidator::Constraints::Dates](https://www.chedong.com/phpMan.php/perldoc/Data%3A%3AFormValidator%3A%3AConstraints%3A%3ADates/markdown))],
        constraints => {
            date_and_time_field       => {
                constraint_method => 'date_and_time',
                params=>[\'MM/DD/YYYY hh:mm:ss pp'], # 'pp' denotes AM|PM for 12 hour representation
            },
        }

## SEE ALSO
    o   [Data::FormValidator](https://www.chedong.com/phpMan.php/perldoc/Data%3A%3AFormValidator/markdown)

    o   [Data::FormValidator::Constraints::DateTime](https://www.chedong.com/phpMan.php/perldoc/Data%3A%3AFormValidator%3A%3AConstraints%3A%3ADateTime/markdown) - This alternative features returning dates as
        DateTime objects and validating against the date formats required for the MySQL and
        PostgreSQL databases.

## AUTHOR
    Mark Stosberg, <<mark@summersault.com>>

    Featuring clever code by Jan Krynicky.

## COPYRIGHT AND LICENSE
    Copyright 2003-2005 by Mark Stosberg

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

