Jump to content

date to string


asmith

Recommended Posts

$a = date('Y-m-d.H-i-s');

 

how can i store the result into a string ?

 

for example :

 

echo $a;

//do a lot of stuff


 

now if i again

echo $a  . this will output new time, 

what i want is the first time $a echoed value , or the first time php put date function value in $a

hard for me to explain , i hope you get what i mean .

i want to make date function value in a string that would be safe and fixed, so every time i echo the string i would have a fixed string, not an up-tp-date  changble date. 

(please note i don't want to store the date in mysql , the get it back from it ,i want to do it all in php)

Link to comment
Share on other sites

create some session variables and store the $a variable in one of those sessions.

 

then check to see if the season has been set; if it has, then set $a to something other then a date and if the season has not been set, let variable $a remain as a date value.

 

try something like this:

 

<?php

start_session();

if (isset($_SESSION["lockeDate"] == "yes"))
{
$a =  $_SESSION["lockenDate"];
}
else {
$a = date('Y-m-d.H-i-s');
$_SESSION["lockenDate"] == $a;
$_SESSION["lockeDate"] == "yes";
}

?>

Link to comment
Share on other sites

both good answers,

 

$a can only be updated by:

$a = date('Y-m-d.H-i-s');

 

therefore, your script must be running this line multiple times. If it's only run once, $a will only contain one value. You will need to post more code for us to help you with some logic that will retain one value.

 

PhREEEk

 

 

so the out put of this :

 

$a = date('Y-m-d.H-i-s');

//do a lot stuff that takes 5 minutes 

echo $a

 

the output of a$ is the 5 minutes earlier ?

 

 

create some session variables and store the $a variable in one of those sessions.

 

then check to see if the season has been set; if it has, then set $a to something other then a date and if the season has not been set, let variable $a remain as a date value.

 

 

yea, session looks will work fine .

Link to comment
Share on other sites

so the out put of this :

$a = date('Y-m-d.H-i-s');
//do a lot stuff that takes 5 minutes 
echo $a

the output of a$ is the 5 minutes earlier ?

 

Yes, if you set $a to the date, then it'll be that date till the end of the page or $a is reassigned.

$a = date(...); // $a is now "2007-12-01.01-59-01"
// Do stuff that takes 2 days
print $a; // will print "2007-12-01.01-59-01"

Link to comment
Share on other sites

I kind screwed-up on my script there a little bit asmith - sorry about that - I didn't test it before I posted it. :-[

 

here's what it should have been:

 

<?php
session_start();

$a = date("Y-m-d.H-i-s");

if ($_SESSION['lockeDate'] == 'yes')
{
$a = $_SESSION['lockenDate'];
}
else {
$_SESSION['lockenDate'] = $a;
$_SESSION['lockeDate'] = yes; 
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.