Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,165,668 members, 7,862,056 topics. Date: Sunday, 16 June 2024 at 07:42 AM

How Do I Make Php Time() Static - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How Do I Make Php Time() Static (1882 Views)

I Develop Static & Dynamic Websites / Understanding Static In Javascript With Examples / I Want To Turn My Static Website Into Responsive Website (2) (3) (4)

(1) (Reply) (Go Down)

How Do I Make Php Time() Static by ANTONINEUTRON(m): 8:55pm On Oct 11, 2016
Please,
How do i make php time() function static

that is, lets say d is 3:00 pm, it would be reading as 3:00 pm through out d execution of the script.
Re: How Do I Make Php Time() Static by beatsbyj2g(m): 9:49pm On Oct 11, 2016
ANTONINEUTRON:
Please,
How do i make php time() function static

that is, lets say d is 3:00 pm, it would be reading as 3:00 pm through out d execution of the script.
Are you trying to like stop time.
Pleadr give an instance of what you are trying to do
Re: How Do I Make Php Time() Static by ANTONINEUTRON(m): 11:00pm On Oct 11, 2016
beatsbyj2g:
Are you trying to like stop time. Pleadr give an instance of what you are trying to do
check diz script.
echo date("h:i:s a",time()); //will return return current time let's say 10:00 pm
i want it to remain as 10:00pm without changing again to 10:01pm .... as long as the script is running, till the user exit.
Re: How Do I Make Php Time() Static by Nobody: 11:40pm On Oct 11, 2016
Santa maria! i don nearly mad finish just trying to think of what this person is saying.
Re: How Do I Make Php Time() Static by guente02(m): 12:42am On Oct 12, 2016
ANTONINEUTRON:

check diz script.

echo date("h:i:s a",time());
//will return return current time let's say 10:00 pm

i want it to remain as 10:00pm without changing again to 10:01pm ....
as long as the script is running, till the user exit.
I thought they said time waits for no man, you think it will wait for a mere script?

2 Likes

Re: How Do I Make Php Time() Static by disco82: 5:44am On Oct 12, 2016
ANTONINEUTRON:

check diz script.

echo date("h:i:s a",time());
//will return return current time let's say 10:00 pm

i want it to remain as 10:00pm without changing again to 10:01pm ....
as long as the script is running, till the user exit.
you can assign time() to a variable at the begining of your script, then you will be using that variable whenever you want.
like x=time()

1 Like

Re: How Do I Make Php Time() Static by Nobody: 6:45am On Oct 12, 2016
disco82:

you can assign time() to a variable at the begining of your script, then you will be using that variable whenever you want.
like x=time()
this is when script exits abi. but the dude says when a user exits - probably session thangs.
Re: How Do I Make Php Time() Static by ANTONINEUTRON(m): 7:40am On Oct 12, 2016
guente02:

I thought they said time waits for no man, you think it will wait for a mere script?
check your post, the time/date u wrote this post written at d heading.
Re: How Do I Make Php Time() Static by ANTONINEUTRON(m): 7:41am On Oct 12, 2016
dhtml18:
Santa maria! i don nearly mad finish just trying to think of what this person is saying.
a correct example is Nairaland time at the of every post
Re: How Do I Make Php Time() Static by guente02(m): 7:57am On Oct 12, 2016
ANTONINEUTRON:

a correct example is Nairaland time at the of every post
The time on every post on nl is na db information na. Like post_time.
Re: How Do I Make Php Time() Static by Dangujba1111: 9:22am On Oct 12, 2016
ANTONINEUTRON:

a correct example is Nairaland time at the of every post
This is an db work not time() function you have first set date using date() function insert into db and fetch thats how nairaland date works
Re: How Do I Make Php Time() Static by ANTONINEUTRON(m): 9:24am On Oct 12, 2016
Dangujba1111:

This is an db work not time() function you have first set date using date() function insert into db and fetch thats how nairaland date works
Yea i've done that and it's working THANKS
Re: How Do I Make Php Time() Static by 2Pr3cise(m): 9:48am On Oct 12, 2016
You can use mysql timestamp for this (YYYY-MM-DD HH:MM:SS) field type to store your time and date variables in mysql.

$sDate = date("Y-m-d H:i:s" )
; // 2016-10-12 09:48:00
mysql_query("insert into `table_name` set `created_on` = '$sDate'" )
;

It also gives you the ability to use mysql functions to compare dates, calculate time differences and so on directly in your mysql query.

Note: Also you can always retrieve the timestamp using strtotime() function.

$result = mysql_query("select `created_on` from `table_name`" )
;
$row = mysql_fetch_row($result)
;
$iTimestamp = strtotime($row[0])
; // 1428390771

1 Like

Re: How Do I Make Php Time() Static by beatsbyj2g(m): 7:53pm On Oct 12, 2016
ANTONINEUTRON:

check diz script.

echo date("h:i:s a",time());
//will return return current time let's say 10:00 pm

i want it to remain as 10:00pm without changing again to 10:01pm ....
as long as the script is running, till the user exit.

Let me guess u want to carry out more Dan 1 operations eg inserting two data sets into separate tables

just get the time

$t = time(); // wen d user enters d script

$use1 = date($format,$t);
$use2 = date($format,$t);
$useN= date($format,$t);

i.e don't call time() inside date(); if you want a static time
Re: How Do I Make Php Time() Static by Sibrah: 9:08pm On Oct 12, 2016
I think what OP needs is to store the time in a variable within the script and use the stored version of the time all through the script. The script must be one that runs for long period for the whole puzzle to make sense.
Re: How Do I Make Php Time() Static by ANTONINEUTRON(m): 10:59pm On Oct 12, 2016
Sibrah:
I think what OP needs is to store the time in a variable within the script and use the stored version of the time all through the script. The script must be one that runs for long period for the whole puzzle to make sense.
I Ave Done That Already, Still It Isn't Working, The Time Continue Working.

I Think D Database Method Is I Save As A String, When The User Exit The Script, I Delete It From The Database.
It's Side-Effect Is, The Table Would Be Littered With Useless Times(When The User Exit The Script Half-way)

AnyWay Am Going With That Method.
Re: How Do I Make Php Time() Static by ugwum007(m): 12:36am On Oct 13, 2016
Sorry it would have been much easier to implement in Java but you are talking python snake men....

Anyway with java, I think this will do:

private static final time t = Date (new LocaltimeDate().getInstance())

When I wake up, I will try if it will work.
Re: How Do I Make Php Time() Static by ugwum007(m): 12:37am On Oct 13, 2016
Sorry it would have been much easier to implement in Java but you are talking python snake men....

Anyway with java, I think this will do:

private static final time t = Date.getTime (new LocaltimeDate().getInstance())

When I wake up, I will try if it will work.
Re: How Do I Make Php Time() Static by directonpc(m): 7:02am On Oct 13, 2016
ugwum007:
Sorry it would have been much easier to implement in Java but you are talking python snake men....

Anyway with java, I think this will do:

private static final time t = Date.getTime (new LocaltimeDate().getInstance())

When I wake up, I will try if it will work.
The guy already has a solution. Which is to store the time to db. I wish people on this forum can understand a question before answering.
Re: How Do I Make Php Time() Static by ugwum007(m): 7:45am On Oct 13, 2016
directonpc:

The guy already has a solution. Which is to store the time to db. I wish people on this forum can understand a question before answering.

Must it involve a database, what if he writes or logs it to a file.
The other people in this forum likes killing rats with one method.
Re: How Do I Make Php Time() Static by directonpc(m): 7:52am On Oct 13, 2016
ugwum007:


Must it involve a database, what if he writes or logs it to a file.
The other people in this forum likes killing rats with one method.
He is asking for something like nairaland post time. So a db will be preferable. Instead of logging to a file.
Re: How Do I Make Php Time() Static by ANTONINEUTRON(m): 4:12pm On Oct 14, 2016
ugwum007:

Must it involve a database, what if he writes or logs it to a file. The other people in this forum likes killing rats with one method.
is there another way of doing this
Re: How Do I Make Php Time() Static by ugwum007(m): 12:54pm On Oct 15, 2016
ANTONINEUTRON:

is there another way of doing this

Just a theory I have in my head, get the instance of time you want. Write it as a string to a file and save. U can read that time from the text file as a string as many times as you want. After the operations, you can delete the text file (use another thread to do that).

Since is php u are asking of and it is probably for website development, u can use database as suggested.
Re: How Do I Make Php Time() Static by Nobody: 1:13pm On Oct 15, 2016
ugwum007:


Must it involve a database, what if he writes or logs it to a file.
The other people in this forum likes killing rats with one method.
session and cookie can do the trick too, or even a log file. It is overkill to use a database for something as basic as this.

1 Like

Re: How Do I Make Php Time() Static by Nobody: 1:17pm On Oct 15, 2016
ANTONINEUTRON:

is there another way of doing this
There is one thing you still do not get my friend, there are many ways of tackling problems in programming. But if we do not know what you are trying to achieve, we cannot just be talking anyhow.
Re: How Do I Make Php Time() Static by ugwum007(m): 5:13pm On Oct 15, 2016
dhtml18:

session and cookie can do the trick too, or even a log file. It is overkill to use a database for something as basic as this.

Thanks

(1) (Reply)

Software Developer Vacancy In An IT Firm. / I'm a very dull programmer. / Learning Java Algorithms:merge Equal And Unequal Arrays.

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 37
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.