CodeIgniter Forums
how to convert values to timestamp type in codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how to convert values to timestamp type in codeigniter (/showthread.php?tid=43983)



how to convert values to timestamp type in codeigniter - El Forum - 07-29-2011

[eluser]mehwish[/eluser]
hi can anyone tell me if i take input from user the year the month and the date then how can these values can be set into such formate 'Y-m-d H:iConfused' so that i can put these values in DB field with type timestamp


how to convert values to timestamp type in codeigniter - El Forum - 07-29-2011

[eluser]regal2157[/eluser]
http://php.net/manual/en/function.mktime.php


how to convert values to timestamp type in codeigniter - El Forum - 07-29-2011

[eluser]danmontgomery[/eluser]
http://php.net/manual/en/function.date.php


how to convert values to timestamp type in codeigniter - El Forum - 07-30-2011

[eluser]Aken[/eluser]
Combination of strtotime() and date().


how to convert values to timestamp type in codeigniter - El Forum - 07-30-2011

[eluser]mehwish[/eluser]
I have written the following code

Code:
$year=$this->input->post("year_textbar");
          $month=$this->input->post("mydropdown_for_month");
          $date=$this->input->post("mydropdown_for_day");
          $hour=$this->input->post("hour");
          $minute=$this->input->post("minute");
          $second=$this->input->post("second");
          echo $int_date = mysql_to_unix($year.$month.$date.$hour.$minute.$second);

and get the following result: 1378133405 what does it mean?


how to convert values to timestamp type in codeigniter - El Forum - 07-30-2011

[eluser]jmadsen[/eluser]
well, since you are using the mysql_to_unix() function, you look that up, then look up any terms you aren't familiar with.

Why did you decide to use the mysql_to_unix() function in this code?

just 'cuz you're new doesn't mean you aren't expected to do your homework before asking questions.


how to convert values to timestamp type in codeigniter - El Forum - 07-30-2011

[eluser]fesweb[/eluser]
Quote:and get the following result: 1378133405 what does it mean?
That 10 digit number is a UNIX timestamp, which is how PHP refers to dates. In your case, it literally refers to a specific time that is 1378133405 seconds after January 1, 1970: url=http://www.unixtimestamp.com/]unixtimestamp.com[/url]

Dealing with dates can be a tricky business, and you will always need to remember that PHP's date functions rely on the UNIX timestamp, so you now have to learn about it and work with it. MySQL formats those same dates in the 'Y-m-d H:iConfused' format. You will need to convert back and forth between those two formats (and others) often. The links that others included above will help you with that.

In my experience, when you don't get the expected result with dates, it is almost always a format or conversion issue.