Welcome Guest, Not a member yet? Register   Sign In
how to convert values to timestamp type in codeigniter
#1

[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
#2

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

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

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

[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?
#6

[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.
#7

[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.




Theme © iAndrew 2016 - Forum software by © MyBB