Go Back   WebMasters.org Forums > Website Design & Development > PHP Forum

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-24-2010, 08:27 AM
Junior Member
 
Join Date: May 2010
Posts: 1
Default How to Convert a PHP String to Date?

Obtain the string you want to convert into a date. This can be through a text box on an HTML form or it might be from a database table.
Store this string in a string variable using the assignment statement. For example, if using a form, $myDate = $_POST["txtDate"];
Define a variable to store the resulting date. Do this using the assignment operator and store a zero in the variable: $resultDate = 0;
Use the strtotime function to convert the string and store it in the date variable: $resultDate = strtotime($myDate);
__________________
o2 sensor
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-25-2010, 01:24 AM
Senior Member gay
 
Join Date: Mar 2010
Posts: 356
Default

Although sometimes do not know what everyone says, but I will always come to see
__________________
I have been looking for mbt shoes, I often use the bad results will often buy a new.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-25-2010, 07:25 AM
Junior Member
 
Join Date: May 2010
Posts: 15
Default How to Convert a PHP String to Date?

Code:
<HTML>
<BODY>
<FORM METHOD="POST" ACTION="CallMe.php">
<TABLE>

<TR>
Date:<BR>
<TD><INPUT TYPE="TEXT" NAME="DATE" VALUE="<?php echo $DATE ?>"></TD>
</TR>

<TR>
<TD ALIGN="CENTER">+</TD>
</TR>

<TR>
<TD><INPUT TYPE="TEXT" NAME="OFFSET" VALUE="<?php echo $OFFSET ?>"></TD>
</TR>

<TR>
<TD ALIGN="CENTER"><INPUT TYPE="SUBMIT" VALUE="="></TD>
</TR>

<TR>
<TD><INPUT TYPE="TEXT" NAME="RESULT"
VALUE="<?php echo date("M j, Y",(strtotime($DATE)+60*60*24*($OFFSET))) ?>" disabled></TD>
</TR>

</TABLE>
</FORM>
</BODY>
</HTML>

Last edited by andrikcode; 05-28-2010 at 09:27 AM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-04-2010, 11:41 AM
Junior Member
 
Join Date: Apr 2010
Posts: 14
Default How to Convert a PHP String to Date?

I basicly want to take three inputs and make them into one date object.

Should I then combine them into one string first?

so would it be
$datestring= $year.$month.$day;

then

$time = strtotime( $datestring );

then
$myDate = date( 'y-m-d', $time ); ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-06-2010, 04:54 AM
Junior Member
 
Join Date: May 2010
Posts: 15
Default

To make them into one date object, what I want is to take three inputs and work accordingly. Into one string, firstly should I combine them?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-06-2010, 11:09 PM
Junior Member
 
Join Date: Jul 2010
Posts: 10
Default

Definitely combine them into one string but make sure you consider what format you want to represent them in. Mysql has a lot of nice time saving functions for this stuff MySQL :: MySQL 5.1 Reference Manual :: 11.7 Date and Time Functions

If your app is already opening a database connection then you can borrow any of these mysql functions to save on your php coding.
__________________
old school fax or email fax?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-07-2010, 02:05 AM
Senior Member gay
 
Join Date: Jun 2010
Posts: 169
Default

Although sometimes do not know what everyone says, but I will always come to see
__________________
cheap uggs and nfl jerseys and cheap uggs!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-07-2010, 11:25 AM
Member
 
Join Date: Apr 2010
Posts: 49
Default

hi..

this questions use full to me also..thanks many for share the knowledge..??? meet again.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 08-14-2010, 02:20 AM
Senior Member gay
 
Join Date: Jun 2010
Posts: 169
Default

thumps up for your article, great post...
__________________
cheap uggs and nfl jerseys and cheap uggs!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 08-31-2010, 09:22 AM
Senior Member gay
 
Join Date: Aug 2010
Posts: 129
Default

Thanks for the info, I appreciate it.
__________________
cheap uggs and uggs on sale and wedding dresses
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:01 PM.



Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
vB Ad Management by =RedTyger=