Вопрос

I'm a designer and clueless in PHP. Tried working around this but cannot get it to work.

I need to change the date format in a process script file for a simple HTML form. Here's the pertinent parts and the small script:

<?php

$date = strip_tags($_POST['date']);
$start = strip_tags($_POST['start']);

mail( ...etc...);
?>

How do I get the $date and $start (starting time for an event) to email me with date as F j, Y and time as g:i a.

It's currently throwing me the defaults in YYYY-MM-DD and 24 hour time. I tried declaring

$start = time("g:i a");

both after and before the variables are stripped of tags for both $date and $start, but it won't process at all then.

Это было полезно?

Решение

Use the strtotime

$new = date('F j, Y g:i a', strtotime($start));

That will take the formatted time, convert to unix and then format again.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top