I am current using CodeIgniter 2.2.2 and I have the following code inside my modal:
$this->createDate = time();
$this->db->insert('someDB_Table', $this);
Where my createDate type is a timestamp (i also tried datetime). But this is giving me all zeros when inserting inside DB. Is there other way to get around this? Like such: 0000-00-00 00:00:00
Try this(array input method)
$my_array = array(
'database_field' => $this->input->post('input_form_field'),
'time_stamp' => date('Y-m-d H:i:s'),
);
$this->db->insert('someDB_Table', $my_array);
I fixed the error:
this->createDate = date("Y-m-d H:i:s");
Apparently Datetime/Timestamp requires a format to be recognizes in time at insertion. So here you go!
It looks like your are storing the date inside the variable "createDate" which is stored in your structure variable $this. So it is quite the same as $this['createDate'] = time();
Try to do :
$this = time();
$this->db->insert('someDB_Table', $this);
or
$this->createDate = time();
$this->db->insert('someDB_Table', $this->createDate);
I haven't tested it but both of them should work. Also check your table column name (Sometimes bugs comes from that).
Otherwise this is how I do it almost every time:
$date = time();
$mysqli->query("INSERT INTO `someDB_Table`(`createDate`) VALUES (`$date`)");
Good luck ;)
Related
I am sending a user provided date in the format MM/DD/YYYY. Example 10/07/2020. I want to store this date in a column of type TIMESTAMP(0) in an oracle database.
I have this in my code:
$medicalClaimDetail = new MedicalClaimDetail();
$medicalClaimDetail->TREATMENT_DATE = new yii\db\Expression('10/07/2020');
$medicalClaimDetail->save();
However I get this exception:
Error Code : 932 Error Message : ORA-00932: inconsistent datatypes: expected TIMESTAMP got NUMBER Position
using strings worked for me.
in db component config i had:
'on afterOpen' => function($event) {
$event->sender->createCommand("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'")->execute();
$event->sender->createCommand("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS'")->execute();
}
in code i set dates and timestamps as strings:
$medicalClaimDetail->TREATMENT_DATE = date('Y-m-d H:i:s', time());
$medicalClaimDetail->save();
I am using devbay's eBay SDK for PHP.
By default SoldReport is returning the last 30 days.
I'm trying to filter the date range to specify one-day/24 hour period.
I'm assuming I need to include a date range filter somewhere in the StartDownloadJobRequest call.
$startDownloadJobRequest = new BulkDataExchange\Types\StartDownloadJobRequest();
$startDownloadJobRequest->downloadJobType = 'SoldReport';
$startDownloadJobRequest->UUID = uniqid();
$startDownloadJobRequest->downloadRequestFilter = new BulkDataExchange\Types\DownloadRequestFilter();
$startDownloadJobRequest->downloadRequestFilter->activeInventoryReportFilter = $activeInventoryReportFilter;
I tried CreateTimeFrom and CreateTimeTo but received an Unknown property CreateTimeFrom error, so I do not believe I can use that for this request.
Anyone know how to filter date range in reports?
edit:
So it looks like startTime and endTime is apart of DownloadRequestFilter
DownloadRequestFilter DateTime
I thought something like this would work..
$datefilter = new BulkDataExchange\Types\DateFilter();
$datefilter->startTime = new DateTime('22-10-2016');
$datefilter->endTime = new DateTime('23-10-2016');
//
$startDownloadJobRequest->downloadRequestFilter->dateFilter = $datefilter;
but this doesn't work and I still get all results.
I am trying to add a contact in Exchange, using the php-ews and the following code:
$request = new EWSType_CreateItemType();
$request->SendMeetingInvitations = 'SendToNone';
$contact = new EWSType_ContactItemType();
$contact->GivenName = $updates['name'];
$contact->Surname = $updates['surname'];
if($updates['email'] != ""){
$email = new EWSType_EmailAddressDictionaryEntryType();
$email->Key = new EWSType_EmailAddressKeyType();
$email->Key->_ = EWSType_EmailAddressKeyType::EMAIL_ADDRESS_1;
$email->_ = $updates['email'];
// set the email
$contact->EmailAddresses = new EWSType_EmailAddressDictionaryType();
$contact->EmailAddresses->Entry[] = $email;
}
$contact->CompanyName = $updates['companyname'];
$contact->JobTitle = $updates['jobtitle'];
$contact->Birthday = $updates['birthday'];
$request->Items->Contact[] = $contact;
$response = $this->ews->CreateItem($request);
Where $updates is an array of strings I have as a parameter.
(I skipped the includes, tell me if you need them.)
Now, the contact gets created and everything works, but the birthday event does not get created automatically in my calendar.
So, I would like to know if there's a simple way to have this done, except the obvious (non-elegant) way of creating it manually.
Thank you in advance,
Riccardo
Could solve this using DateTime in the right format as expected in the comments.
$contact->Birthday = (new DateTime($updates['birthday']))->format(DATE_W3C);
https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/time-zones-and-ews-in-exchange
The time zone specified in the value of dateTime elements can take three forms. You can read all the details in XML Schema Part 2: Datatypes Second Edition, but to paraphrase:
Universal Coordinated Time (UTC): Specified by 'Z'. For example, 2014-06-06T19:00:00.000Z
Specific time zone: Specified by '+' or '-' followed by hours and minutes. For example, 2014-06-06T19:00:00.000-08:00
No time zone: Specified by the absence of any time zone. For example, 2014-06-06T19:00:00.000
I have the following code producing this error: Fatal error: Call to a member function setTimeZone() on a non-object in C:\wamp\www\grid2.php on line 58
I am trying to set up this function to take in a date string as below, apply the time offset, then output it back out in the format set up in the function call... but no luck.
<?php
if (!session_id()) session_start();
$_SESSION["timeoffset"] = "Europe/Amsterdam";
function formatDate($date, $format){
// use the the appropriate timezone for your stamp
$timestamp = DateTime::createFromFormat($format, $date, new DateTimeZone('UTC'));
// set it to whatever you want to convert it
$timestamp->setTimeZone(new DateTimeZone($_SESSION["timeoffset"]));
echo $timestamp->format($format);
}
formatDate('2012-10-14T21:15', 'Y-m-d\TH:i');
?>
I am also trying to figure out how return the string with a certain number of added minutes amount of minutes.
So the string "2012-10-14T21:15" would have 5 minutes added = "2012-10-14T21:20"
Any help would be greatly appreciated!
Jeff
DateTime::createFromFormat will return false on failure. This means that:
DateTime::createFromFormat($format, $date, new DateTimeZone('UTC'));
has failed and that $timestamp is false (var_dump($timestamp) will show you). Without knowing what you're passing in as your parameters for function formatDate, I don't think anyone will be able to figure out exactly what you're doing wrong.
Use this rather
$timestamp->setTimeZone(new DateTimeZone("Europe/Amsterdam"));
I think the sessions array isn't returning the string Europe/Amsterdam.
Do the debugging
public function updateAuction($id)
{
$AuctionsTable = Doctrine_Core::getTable('auctions');
$auction = $AuctionsTable->find($id);
$auction->ends_at += 10;
$auction->save();
}
I'm using Doctrine to get a record from the database.
I need to increase number of seconds on this records ends_at column, which is a date type.
+= of course didn't work. What is the quickest way to add, let's say, 10 seconds to ends_at variable? And having handled all the other nuisances that might appear (59 + 10 = 69 seconds).
Perhaps I should use mysql's addtime() function? But is that implemented with Doctrine? Didn't find anything about addtime() on doctrine.
Convert the value from the DB into a DateTime object in PHP
Use the DateTime::add function to add the seconds
Put the resulting value back into the DB
try this:
$sec = new Zend_Date($auction->ends_at, Zend_Date::SECOND);
$auction->ends_at = $sec->addSecond(10);
$auction->save();