<div>After all search, I found it really difficult to deal with date. I am trying to store the date in MySql table as varchar type and placeholder as %s.</div>
<div> </div>
<div>However I need two functions to convert date from array format to string format (required while storing into table) and string format to array format (Required while showing it in form).</div>
<div> </div>
<div>The below code does that for me.</div>
<div> </div>
<div> </div>
<div><strong><em>function dateArrToStr(&$customDateArr)<br>{<br> $strDate = t($customDateArr['day']).t('- ').t($customDateArr['month']).t('-') . t($customDateArr['year']);<br> return $strDate;<br>
}</em></strong></div>
<div><strong><em></em></strong> </div>
<div><strong><em></em></strong> </div>
<div><strong><em>function dateStrToArr (&$customDateStr, $length)<br>{<br> $convDate = array();<br> $index = 0;<br> $customToken = t('');<br> $dashPosition = 0;<br> <br> for($index = 0; $index < $length; $index++)<br>
{<br> if($customDateStr[$index] == t('-'))<br> {<br> if($dashPosition == 0)<br> {<br> //Set the day<br> $dashPosition++;<br> $convDate['day'] = $customToken;<br> }<br> else if ($dashPosition == 1)<br>
{<br> //Set the month<br> $dashPosition++;<br> $convDate['month'] = $customToken;<br> }<br> $customToken = t('');<br> }<br> else<br> {<br> $customToken = t($customToken) . t($customDateStr[$index]) ;<br>
}<br> }<br> //Set year<br> $convDate['year'] = $customToken;<br> return $convDate;<br>}</em></strong></div>
<div> </div>
<div> </div>
<div>Regards</div>
<div>Austin<br><br></div>
<div class="gmail_quote">On Mon, Mar 28, 2011 at 8:36 AM, Austin Einter <span dir="ltr"><<a href="mailto:austin.einter@gmail.com">austin.einter@gmail.com</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div>Hi All</div>
<div>I have a date field in my form.</div>
<div>How do I store/retreive the value into/from MySQL.</div>
<div> </div>
<div>On google search, I saw people are suggesting to use either "int" or "datetime" type.</div>
<div>Please suggest which one needs to be used.</div>
<div> </div>
<div>If I use int (I hope core uses int), while storing can I just store "form['values']['date1']" as %d and while retreivin, what are the related apis to convert back to date.</div>
<div> </div>
<div>Regards</div>
<div>Austin.</div><font color="#888888">
<div> </div>
<div> </div></font></blockquote></div><br>