Skip to content

strtotime give wrong value for ("2024-04-01") or ("2024-03-31") : visible when making a substraction #13066

Closed as not planned

Description

Description

The following code:

<?php
			$date_fin = strtotime("2024-04-01") - strtotime("2024-03-31");
			echo "date_fin=".$date_fin."\n";

Resulted in this output:

date_fin=82800

But I expected this output instead:

date_fin=86400

PHP Version

php 7.4.33

Operating System

5.4.0-163-generic #180-Ubuntu SMP Tue Sep 5 13:21:23 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Activity

  1. ghost added on Jan 2, 2024
  2. damianwadley commented on Jan 2, 2024

    @damianwadley
    Member

    A number of countries and timezones had a DST transition on March 31st, such as the one you're using. For them the day was, in fact, 82800 seconds long.

  3. damianwadley commented on Jan 2, 2024

    @damianwadley
    Member

    I don't know what you're trying to do but I expect that code there will be very, very incorrect.

    Dates are hard. Might I suggest looking for help on StackOverflow or elsewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions