Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8077623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:31:36+00:00 2026-06-05T15:31:36+00:00

How do you get today’s date, as a date object? I’m trying to compute

  • 0

How do you get today’s date, as a date object?

I’m trying to compute the difference between some start date and today. The following will not work, because getdate() returns an array and not a date object:

$today = getdate();           
$start = date_create('06/20/2012');
$diff = date_diff($start, $today);

echo($today . '<br/>' . $start . '<br/>' . $diff);

Output:

Array ( [seconds] => 8 [minutes] => 1 [hours] => 16 [mday] => 11 [wday] => 1 [mon] => 6 [year] => 2012 [yday] => 162 [weekday] => Monday [month] => June [0] => 1339455668 )

DateTime Object ( [date] => 2012-06-20 00:00:00 [timezone_type] => 3 [timezone] => America/Los_Angeles )

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:31:38+00:00Added an answer on June 5, 2026 at 3:31 pm
    new DateTime('now');
    

    http://www.php.net/manual/en/datetime.construct.php

    Comparing is easy:

    $today = new DateTime('now');
    $newYear = new DateTime('2012-01-01');
    
    if ($today > $newYear) {
    
    }
    

    Op’s edit
    I just needed to call date_default_timezone_set, and then this code worked for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the following: [today's date]___[textfilename].txt from the following code: using
I am trying to get today's date with some specific format: var d =
i have the following code def get(self): date = datetime.date.today() loc_query = Location.all() last_cursor
I'm able to get today's date using the following in Objective-c: NSDate *date =[NSDate
I am using the following code to get today's date. Calendar cal = Calendar.getInstance();
Im trying to get the closest date to today from array dates. Example: Today
In php i can get today date/day by using : $today = date('D, Y-m-d');
I've been trying to get setup with Ruby on Rails today, but I think
I have a variable in my Sinatra application: get '/' do @agenda_date = Date.today
I though it would be very simple but I can not get it today.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.