Jump to content

Setting created date via API results in zeroed-out date


Recommended Posts

Posted

I needed to set a single article's created date, so I used this code from one of Ryan's forum posts:

$page = $pages->get("/news/blah/");
$time = strtotime("2012-11-15"); // or whatever date you want
wire('db')->query("UPDATE pages SET created=$time WHERE id={$page->id}");

The result was a date of 0000-00-00. I went in and changed it via PHPMyAdmin. Any ideas why that would happen?

Posted

I'm not sure why you're converting that date to Unix timestamp, but that's probably why this is failing. Try something along these lines instead:

wire('db')->query("UPDATE pages SET created='2012-11-15' WHERE id={$page->id}");

The type of db field created is timestamp, which doesn't by default accept Unix timestamps (...) as it's value.

  • Like 2
Posted

Sorry Marc, I'm guessing I wrote the wrong thing in some other thread. If you know what post that was, let me know and I'll correct it. Teppo's code is correct.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...