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
Related
I have a date field that I would like to express through a MySQL Query or as a PHP function as yyyymmdd, basically without any - or /, all the examples I can find include these.
I could build it a piece at a time, so y.m.d, but thought someone here might have come across this for, its basically a naming convention for network folders, hence why no special characters.
Thank you in advance
You can use PHP's DateTime Class:
echo (new DateTime($dateField))->format('Ymd');
SQL you can use DATE_FORMAT
DATE_FORMAT(NOW(),'%Y%m%d') //20150513
PHP you can use using date
echo date('Ymd'); //20150513
You can use strtotime() and date() function like this:
$time = strtotime($yourdatefield);
$date = date('Ymd', $time);
I have searched high and low on how to do this.
I am using the following datepicker script. http://jqueryui.com/datepicker/
Unfortunately it formats the date like so xx/xx/xxxx. However, the date function in mysql saves the date like so xxxx-xx-xx. I used str_replace to replace the / to -. My deli-ma is trying to figure out now how to convert my variable $editsentdate from xx-xx-xxxx to the mysql date format xxxx-xx-xx. When I just send the variable to my DB like it is it stores it as 0000-00-00 which I am sure is b/c that it is not formatted by Ymd. Any help would be appreciated.
$editsentdate = str_replace('/','-',$_POST['edit_sent_date']); // xx-xx-xxxx
Use PHP's function date(). Example: date("Y-m-d", strtotime($_POST['edit_sent_date']))
$editsentdate = date("Y-m-d",strtotime($_POST['edit_sent_date']));
In datepicker, you can format the date
$('#datepicker').datepicker({ dateFormat: 'yy-mm-dd' });
More info here
There is also a createFromFormat function in PHP. You could initiliaze the date and then format it any way you want.
See PHP - DateTime createFromFormat
<?php
$date = DateTime::createFromFormat('j-M-Y', '15-Feb-2009');
echo $date->format('Y-m-d');
?>
$mysql_date = preg_replace('~^([0-9]{2})/([0-9]{2})/([0-9]{4})$~',
'$3-$2-$1', $_POST['edit_sent_date']);
Assuming the date format is reliable. Other answers might be more reliable but this is a different way... just FYI.
i'm compiling a church register and the dates are in this format yyyy-mm-dd
example. 1978-03-27 .I need to make it 27th March,1978. Any php script to help me out?
I tried MSEXcel but messes it up. thanks (anyway..i'm getting it from a database) so i would be glad if i have it been read from a database or a file of dates.
Try with:
$input = '1978-03-27';
$timestamp = strtotime($input);
$output = date('dS F, Y', $timestamp);
Reference to date format: php.net
Try this:
$in = '1978-03-27';
$out = date('jS F Y',strtotime($in));
var_dump($out);
date() formats your output, and strtotime() converts your input to a timestamp. Keep in mind this will only work for values from 1970-01-01. If you want to work with "older" dates, you have to parse the input manually and generate the output you require.
I need help to convert a formatted date format as stated below:
How can I convert 2010-02-06 14:44:43 to dd/mm/yyyy
Thanks
Great place to start for this type of general information, php docs, specifically related to your date format question: http://us3.php.net/manual/en/function.date.php
-- Edit --
Answer with substr() forced me to do the work... using substr() to format a date is not the best option as PHP has built-in functions for that.
var_dump(date('d/m/Y', strtotime('2010-02-06 14:44:43')));
$date = new DateTime('2010-02-06 14:44:43');
echo $date->format('d/m/Y');
Output:-
06/02/2010
See the manual
Try this:
<?php
$time = strtotime('2010-02-06 14:44:43');
echo date('d/m/Y',$time);
?>
in my webpage i need to calculate the day[ie. SUN,MON,TUE...] from the date .. The date is in ['06/22/2009'] this format ? How can i calculate it in to day[That is it will show me MON] in php . Please help me to find out . Thanks in advance..
First, you need to parse the string '06/22/2009' into a timestamp, possibly using strtotime():
$dt = strtotime('06/22/2009');
Then, you can format the timestamp using date():
$day = date("D", $dt);
If you especially want it in uppercase, use strtoupper():
print strtoupper($day);
For future viewers, I think this will be more helpful.
echo date('l', strtotime('11/20/2017'));
Use the date
http://au.php.net/manual/en/function.date.php
and strtotime http://au.php.net/strtotime
functions
pls check the funcion. the out put is showing the current day.pls tell me the given date dau in the date("D",$dat)