Date format on OpenX API addCampaign method - php

I'm creating a campaign through the OpenX API, and so far so good but i need to set an end date to the campaign, via the endDate parameter; the thing is: i don't know what i should bind to the parameter on the API call. I tried using this: $date = date("Y-m-d H:i:s",strtotime(date("Y-m-d H:i:s") . $date_threshold)); where $date_threshold is something like "+1 month", but the endDate won't appear on the OpenX panel.
What kind of data do i need to bind to that parameter so it's correctly inserted on the OpenX database?
Thank you in advance.

Glad you got it to work -- Just as a note: I'm not sure how you handle the general XML-RPC communication, but what I do is pass a date string into PEAR's XML-RPC, something like:
new XML_RPC_Value('20100413T00:00:00', 'dateTime.iso8601')

Turns out it is a simple DateTime(), so nothing of that would work, because the API wants a Date object, not string!
So, the code i sent on the question turns into:
$date = new DateTime();
$date.modify($date_threshold);

Related

Php time and datatime object

So,
I know a lot of requests and question has been askeb about this subject but none really worked for my case... I'm working on a liscensing api with php (supposed to be easy) and I get a string date (2000-01-01) from my db and the length of the subscription. So I'm creating a DateTime Object with it using this :
$created_at = date_create($result["created_at"]);
date_add($created_at, date_interval_create_from_date_string($result["length"]." days"));
But for some unknowed reason, It seems I can't get the current date in a DateTime object so I can just compare them with <>=. Even if I use date_sub() or date_diff() It still require two DateTime object. I'm really deseperate at this point so I figured I could ask for some help.
Hope I didn't miss anything obvious
You can use the 'now' attribute,
$today = new DateTime('now'); to get the current time.
Don't forget to set your timeregion in your php.ini to be able to get the right time.
And if you want to compare them, you can use date_diff and then
$var->format('%r') to get the value.
%r is going to be empty if the result is positive.
Good luck!

How to format date-time for RFC2445 in PHP

I am working on Google Calendar API using its PHP library and I need to set a recurring event for which I have to create a RRule string which should be of following format:
RRULE:FREQ=WEEKLY;UNTIL=20110701T170000Z
I am unable to create the date in above format. I literally tried all methods like:
date('YmdHis');
date(DATE_RFC2822);
date('c');
But Google doesn't accept any of above formats. I need to make it like: 20110701T170000Z. Can anybody help me on this?
Thanks
This is your date format:
date('Ymd\THis\Z')
becomes
20150429T154315Z
Look at the examples here: http://php.net/manual/de/function.date.php
Are you able to concatenate two strings together and form the required datetime string in RFC2822?
<?php
$ymd = date('Ymd');
$hms = date('His');
echo $ymd."T".$hms."Z"; //Will output YYYYMMDDTHHMMSSZ
?>
Let me know if this works! :)
Try this:
date('Ymd\THis\Z', $timestamp);
or
date('Ymd\THis\Z');
if you want the current timestamp

PHP picking data from a string

Basically I am wondering how I would go about taking pieces of a string and putting them into another variable. I need to do this as, from API I am using, you are given the date of channel creation and I would like to take the data from this, but it is displayed in a strange way.
Here is what is given by the API:
2012-06-11T13:36:21Z seconds
^^ That is what I need to change so that I can display it in a nicer way. i.e. 11-06-2012.
Thanks.
P.S. This is twitch API if it matters.
You could use two PHP functions: "strtotime()" and "date()"
$timestamp = "2012-06-11T13:36:21Z";
echo date("jS F, Y", strtotime($timestamp));
The above would echo "11th June, 2012"
Look up the createFromFormat() function for DateTime.

Constant Contact API Error:"Scheduled date is before the current time."

We're currently using the API to create campaigns, and all seems to be working fine. When we try to schedule the campaign, however, we are getting errors. When we try to use the example format for 'schedule_date' from one of the SDK libraries:
$time = date('Y-m-d\TH:i:s\.000\Z', strtotime("+1 hour"));
$schedule = new Schedule();
$schedule->scheduled_date = $time;
We get an error that saying
Scheduled date is before the current time.
When we echo the $time to the screen, we see that it is in fact one hour in the future. (We are in EST).
When we try to use the standard PHP format for ISO-8601 (lowercase 'c') we get and error saying
"#/scheduled_date: Value is not a valid ISO-8601 date time format."
$dt = date('c', strtotime("+1 hour"));
schedule = new Schedule();
`$schedule->scheduled_date = $dt
I'm sure there is something obvious we are missing, so any help would be greatly appreciated.
I would definitely try using the DateTime class (http://php.net/manual/en/class.datetime.php) in conjunction with DateTimeZone to see if that alleviates the issue.
We've also updated our Date/Time parser to accept more formats, which should hopefully take care of the issue you ran into when trying to use date('c')
If you keep running into issues let me know!
Thanks,
Mike

PHP: strtotime formatting

I am trying to put a readable time and date as part of a file name (in php). I am having all kinds of trouble with this and was hoping someone could help. I have tried several different recommendations that I have read around the internet (plus I read the manual) but I really haven't gotten anything to work right. Right now I have this:
$Time=strtotime("now");
$date=DateTime::createFromFormat('m/d/Y H:i:s', '7/24/2012 14:40:30');
$date_readable=$date->$Timestamp();
At that point I then add $date_readable to a file name. It compiles and runs but it doesn't format the date at all. It still gives it as a timestamp.
Any suggestions on how to make this work?
you can do it with simple date function for example
$time = strtotime("now");
$formatDate = date('F jS, Y h:i:s A', $time);
echo $formatDate;
this will print something like
July 25th, 2012 1:02:29 am
DateTime class is more powerful then using simple date function, as DateTime class offers powerful API's plus it is object oriented. however for simple date conversions i would stick to php's date function. as that could do my purpose.
for more formatting option have a look at this link http://www.php.net/manual/en/function.date.php#refsect1-function.date-parameters

Categories