Jump to content

Recommended Posts

Posted

I got a field called entrega and defined as DateTime (Profields Table) with the following parameters

dateInputFormat=Y-m-d
timeInputFormat=H:i
dateOutputFormat=Y-m-d
timeOutputFormat=H:i
datepicker=3
defaultToday=0
yearRange=-10:+10
placeholder=
textformatters=TextformatterEntities
default=

when I try to save same data with

$newRow->entrega = date("Y-m-d H:i");

I get 

2018-05-30 00:00

if I do 

echo date("Y-m-d H:i");

I get the right date and time.

Thanks.

Posted

When I set DateTime fields from API I just use the unix timestamp like:

$newRow->entrega = time();

Well, doesn't help if your time source is a string.

  • Like 1
Posted

Can you give me more code context? I've just added that to my previous test code and it works quite well:

<?php namespace ProcessWire;

$test = $page->protabla->makeBlankItem(); // getNew();
$test->name = date('D, d M Y H:i:s');
$test->notes = 'my note';
$test->entrega = time(); // date("Y-m-d H:i");
// $test->save();
$page->of(false);	// required for page save
$page->protabla->add($test);
$page->save('protabla');	// only save that field
$page->of(true);

$content = "<h4>{$page->title}</h4>";
$content .= "<table>";
foreach($page->protabla as $pt)
	{
	$content .= "<tr><td>{$pt->name}</td><td>{$pt->notes}</td><td>{$pt->entrega}</td></tr>";
	}
$content .= "</table>";

 

  • Thanks 1
Posted

I've changed the type to Date and back to DateTime and now is working as it should.

Thanks, hope I can help you in the future.

 

 

  • Like 1

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...