0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHP で日付が正しいかをチェック (YYYYMMDD)

Last updated at Posted at 2021-05-31

PHP で日付が正しいかをチェック (YYYYMMDD)

<?php
$date = "20210321";
validateDateFormat($date);
$date = "202103213333";
validateDateFormat($date);
$date = "20210";
validateDateFormat($date);
$date = "2010aass";
validateDateFormat($date);
$date = "20101333";
validateDateFormat($date); 
function validateDateFormat($date)
{
    // 右0埋め
    $_date = str_pad($date, 8, 0, STR_PAD_RIGHT);
    // 8桁以上の場合は切り詰め
    $_date =substr($_date, 0,8);
    print($_date)."\n";
    // checkdate の引数は int
    $year = intval(substr($_date, 0,4)); 
    var_dump($year);
    $month = intval(substr($_date,4,2));
    var_dump($month);
    $day = intval(substr($_date, 6,2)); 
    var_dump($day);
    if(checkdate($month, $day, $year) === false)
    {
        echo 'NG : 日付が正しくありません。'."\n";
    }
    else
    {
        echo 'OK!'."\n";
    }
}

perl DBD:Pg

https://metacpan.org/release/TURNSTEP/DBD-Pg-3.15.0/source/README
https://base64.work/so/perl/3606027

# DBI_DSN                     dbi:Pg:db="postgres";port=5440;host=localhost/dbdpg_test_database/data/socket
# DBI_USER                    jgp
# DBI_USER=<username>
# DBI_PASS=<password>
cpan YAML
cpan Test::Simple
cpan DBD::Pg
export POSTGRES_HOME=/var/lib/pgsql/13
export PATH=$PATH:/usr/pgsql-13/bin
export DBI_DSN='dbi:Pg:db="postgres";port=5432;host=localhost'
export DBI_DSN='dbi:Pg:dbname=testdb;;port=5432;'
export DBI_USER='postgres'
export DBI_PASS='postgres'
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?