Welcome Guest, Not a member yet? Register   Sign In
Working with gmt time zone
#1

[eluser]xtremer360[/eluser]
I'm working with dates in my database that are stored as gmt date times and trying to find the function that can turn that time after I take it out into a timestamp so I can run this if statement.

Code:
if(strtotime($user_data->lock_date) > time())

How the lock_date gets set is like this:
Code:
$wait_time = time() + (60*15);
$this->users_model->lock_out_user($post_username, gmdate('Y-m-d H:i:s'), $wait_time);


#2

[eluser]johnpeace[/eluser]
i like using MySQLs UNIX_TIMESTAMP function for conversions.
#3

[eluser]DarkManX[/eluser]
whats wrong with strtotime?
#4

[eluser]johnpeace[/eluser]
Nothing, but why do in PHP what you can accomplish with the DB engine? The DB engine's responsibility is to return data...if it can return data in the format I need, I let it, obviating the need for formatting in my application code.
#5

[eluser]DarkManX[/eluser]
ci comes with some nice date helpers, you should use it. if you need to format some other columns of the data, you will do it in the sql-statement also? so if you have to split the name? there is no need to seperate the format logic in two sections. just keep it all in the php.
#6

[eluser]johnpeace[/eluser]
[quote author="DarkManX" date="1346165274"]there is no need to seperate the format logic in two sections. just keep it all in the php.[/quote]

Why?

If my controller's logic is going to work with dates as integer unix timestamps, why should I retrieve anything else from the DB except a timestamp for that value?
#7

[eluser]DarkManX[/eluser]
as i told, you should maintain consistency. it was an example... this time you just need the timestamps but next time you may need to parse a text or something and format the date to timestamps. why would you wanna have formating the text in the controller and formating the date in the sql? that doesnt make any sense.
so, you will format both in the controller next time, but this time you format in the sql, that bad coding style. but ofc, you can do whatever you want with your app.
#8

[eluser]xtremer360[/eluser]
[quote author="DarkManX" date="1346165274"]ci comes with some nice date helpers, you should use it. if you need to format some other columns of the data, you will do it in the sql-statement also? so if you have to split the name? there is no need to seperate the format logic in two sections. just keep it all in the php.[/quote]

Yes I was looking at them but for the line I need I'm not sure what I need to use for this line of code?
#9

[eluser]DarkManX[/eluser]
try to use human_to_unix()
#10

[eluser]xtremer360[/eluser]
First made I should establish on whether or not I should be storing my datetimes in GMT?




Theme © iAndrew 2016 - Forum software by © MyBB