最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Count time from registration date to today

programmeradmin2浏览0评论

I would like to add to the user profile the time from registration to the current day in the format:

With us: 7 years 3 months 2 weeks 6 days

OR

With us: 1 year 1 month 1 week 1 day

Me a bit helped this post Count days from registration date to today, but there countdown goes only in days.

I would like to add to the user profile the time from registration to the current day in the format:

With us: 7 years 3 months 2 weeks 6 days

OR

With us: 1 year 1 month 1 week 1 day

Me a bit helped this post Count days from registration date to today, but there countdown goes only in days.

Share Improve this question asked Sep 21, 2019 at 19:27 cogorihawcogorihaw 1
Add a comment  | 

1 Answer 1

Reset to default 0

Just gave an example of how to do it:

$today_date      = new DateTime( date( 'Y-m-d', strtotime( 'today' ) ) );
    $register_date  = get_the_author_meta( 'user_registered', get_current_user_id() );
    $registered = new DateTime( date( 'Y-m-d', strtotime( $register_date ) ) );
    $interval_date   = $today_date->diff( $registered );
        if( $interval_date->days < 31 ) {
            echo 'With us ' . $interval_date->format('%d days');
            }
        elseif( $interval_date->days < 365 ) {
            echo 'With us ' . $interval_date->format('%m months %d days');
            }
        elseif( $interval_date->days > 365 ) {
            echo 'With us ' . $interval_date->format('%y years %m month %d days');
            }
发布评论

评论列表(0)

  1. 暂无评论