Jump to content

Setting created date via API results in zeroed-out date


MarcC
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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