Welcome Guest, Not a member yet? Register   Sign In
date problem
#1

[eluser]Bigil Michael[/eluser]
i have date like this 2011-05-14
i want to convert it into datetime format
like this 2011-05-14 00:00:00

can anyone help me??
i tried a lot... but no result......
#2

[eluser]d1a8lo24[/eluser]
you can do the following

Code:
$somedate = strtotime('2011-05-11');

echo date("Y/m/d h:i:s a", $somedate);

this will return something like 2011/05/11 12:00:00 pm or am
#3

[eluser]Bigil Michael[/eluser]
thanks.

now iam doing a project to purchase products .

after a purticular time[eg: 2011-05-14 07:30:00] the product become inactive and nobody can't purchase that product

now iam confused that which one i select in the database

datetime field or 2 seperate field date and time ????

also i want to show remaining time to purchase that product..

sorry for my bad english.

can any one suggest a method.

thanks in advance....
#4

[eluser]d1a8lo24[/eluser]
I'm a little confuse but if I understand a little of what you're saying then use an int field to store time.
When you deal with dates and time the best approach is to use time() instead of actual dates.
Most applications that keep track of time use the int field in a database and store the date and time in a unix time stamp and always in GMT time.
#5

[eluser]Bigil Michael[/eluser]
then i convert the date time into timestamp.ok
#6

[eluser]d1a8lo24[/eluser]
You could if you want to, know that MySQL timestamps are base on local time not GMT unless you configure your database to do so.

Best way is to do an INT field and then use now() from CI or time() from PHP to populate.

In my case I have an application that lets people buy and download items the links have an expiration time so i use 3 int fields 1 to keep track when the item, order, link was created, the 2nd one to keep track on when it was updated and the last one i use to keep track of its expiration.

Know this MySQL only allows you to have 1 timestamp per table so depending on your application keep that in mind.

I started using INT fields since i had a lot of problems when searching and when doing complicated oprations and using operators like >, <=.
#7

[eluser]Bigil Michael[/eluser]
eg:
now i have time like this
$hour = 10;
$minutes = 10;
$seconds = 10;

can u tell me how i convert this into a time stamp value?
#8

[eluser]d1a8lo24[/eluser]
A time stamp is the year / month / date hour:minuteConfusedeconds in seconds

So in other words you need a date in order to create a time stamp the hours, minutes and seconds are there to be more precise on what you want.

In this case lets say your item for sale.

Your item will be for sale for only 4 hours today which is 1305357142 as a unix time stamp which in turn is turn is equal to 2011-05-14 07:12 AM

So the field that holds the expiration date needs to have a unix time stamp that is 4 hours in the feature.
Well we now do some simple math like 60*60*4 = 14400.

Now you add this total to your unix time stamp and you get 1305371542 which will equal to 2011-05-14 11:12 AM

So you can do something like if now() or time() is >= to expiration field disable item else the itm will still be available.

This is just a simple exmaple but i hope you get the idea why a unix time stamp is better to use for many reasons
#9

[eluser]d1a8lo24[/eluser]
See also the users guide date helper for more info
http://ellislab.com/codeigniter/user-gui...elper.html

and also phps date time functions
http://www.php.net/manual/en/ref.datetime.php
#10

[eluser]Bigil Michael[/eluser]
thanks.thank you so much for your great suggestions




Theme © iAndrew 2016 - Forum software by © MyBB