PHP String to date conversion

Allen S

I'm about to pull my hair out people. I've got a form where people select a day and a month from the dropdown menu, and the current year would automatically get concatenated.

On the server I've got this:

$received =  date("Y")."-".$_POST['month']."-".$_POST['day'];
$date = strtotime($received);

$newformat = date('Y F j',$date);
echo $newformat;

Let's say $_POST['month'] == 'April' and $_POST['day'] == '5'

The output always comes out like this:

2013 April 1 (ie the day defaults to 1).

Interestingly if $_POST['day'] == '24' then the output is:

2013 April 2

It's as though it just looks at the first digit.. Any ideas would be greatly appreciated!

James

Is your issue that your "Month" variable is a string instead of an integer, but you are putting it in the date as if it's an integer? 2013-April-5... Try just putting in a 4 instead of April.

Update

To answer your question, you can have your client updated to have options like <option value="1">January</option>, or update your PHP to process it like:

<? $received =  $_POST['month']." ".$_POST['day']." ".date("Y");
$date = strtotime($received);

$newformat = date('Y F j',$date);
echo $newformat; ?>

I think that will work.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Sql Server string to date conversion

分類Dev

Notice: Array to string conversion with date

分類Dev

Java String Date conversion issue

分類Dev

Java - SimpleDateFormat string to Date to mills conversion

分類Dev

PHP date() to Excel serial format conversion

分類Dev

Removing date from string in PHP

分類Dev

oracle to_date conversion showing literal does not match string format

分類Dev

conversion failed when converting date and/or time from character string in xml

分類Dev

Number to Words Conversion (Indian Rupee) decimal String issue in php

分類Dev

PHP - Convert this string to another date/time format

分類Dev

PHP date_format(): How to format date from string value

分類Dev

Date conversion to a different locale

分類Dev

DATE CONVERSION SCALA

分類Dev

Conversion of date formats

分類Dev

Conversion failed when converting date and/or time from character string - but no idea why

分類Dev

Wondering what the default post date PHP string for Wordpress is?

分類Dev

String to PAnsiChar conversion trouble

分類Dev

String conversion returns null

分類Dev

Faster conversion to string

分類Dev

Array to String conversion in codeigniter

分類Dev

Date conversion and subtraction in shell script

分類Dev

bigInt to date conversion giving errors

分類Dev

Excel Date& Time Conversion

分類Dev

String to Class: Conversion Class or Base Conversion Method?

分類Dev

Conversion from string to generic type

分類Dev

How to reverse hash to string conversion?

分類Dev

pl/sql string conversion - regex

分類Dev

datenum and matrix column string conversion

分類Dev

JAVA string encoding conversion issues

Related 関連記事

ホットタグ

アーカイブ