Link to home
Start Free TrialLog in
Avatar of LostTime
LostTime

asked on

Adding a DataStamp in PHP to an Access DB.

I'm trying to update a table in access with a time stamp and i can't seem to get the formating correct. can someone help?
$TimeStmp = date("Y")."-".date("m")."-".date("d")." ".date("H").":".Date("i").":".date("s").".000"; 
 # print $TimeStmp;
  
  $sqlLock = "UPDATE ".$tblNameLock." SET Lock = 'Y', TimeStamp = '".$TimeStmp."' WHERE Conc='".$FC."'";
  #print "<br>". $sqlLock;
  odbc_exec($conn,$sqlLock);

Open in new window

Avatar of EverLearningCodeMonkey
EverLearningCodeMonkey
Flag of Canada image

Hi LostTime,

Access, as I recall, uses # to delimit date/time fields i.e. #2009-04-30# instead of '2009-04-30' like most other databases.

Give that a shot.

Also, a little tip about phps date function, you should be able to use this and get the same result:
$TimeStmp = date("Y-m-d H:i:s.000");

Open in new window

Avatar of LostTime
LostTime

ASKER

thanks for the tip about Date functions.

I've tried # and ' and '# and #' none of them seem to work. i've also tried different date formats. I had PHP pull a date from Access and i got the Format YYYY-DD-MM HH:MM:SS but i've also tried using MM first and / instead of -.
ASKER CERTIFIED SOLUTION
Avatar of EverLearningCodeMonkey
EverLearningCodeMonkey
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NerdsOfTech
Access Date/Time Format Example =

#5/12/95 6:00:00AM#
Here you go
$TimeStmp = '#'. date("n")."/".date("j")."/".date("Y")." ".date("g").":".Date("i").":".date("s").'#'; 
echo $TimeStmp;
  
$sqlLock = "UPDATE ".$tblNameLock." SET Lock = 'Y', TimeStamp = '".$TimeStmp."' WHERE Conc='".$FC."'";
echo "<br>". $sqlLock;
odbc_exec($conn,$sqlLock);

Open in new window

Oops USE THIS INSTEAD
$TimeStmp = '#'. date("n")."/".date("j")."/".date("Y")." ".date("g").":".Date("i").":".date("s").date("A").'#'; 
echo $TimeStmp;
  
$sqlLock = "UPDATE ".$tblNameLock." SET Lock = 'Y', TimeStamp = '".$TimeStmp."' WHERE Conc='".$FC."'";
echo "<br>". $sqlLock;
odbc_exec($conn,$sqlLock);

Open in new window

If the year is two digit (older versions) USE:
$TimeStmp = '#'. date("n")."/".date("j")."/".date("y")." ".date("g").":".Date("i").":".date("s").date("A").'#'; 
echo $TimeStmp;
  
$sqlLock = "UPDATE ".$tblNameLock." SET Lock = 'Y', TimeStamp = '".$TimeStmp."' WHERE Conc='".$FC."'";
echo "<br>". $sqlLock;
odbc_exec($conn,$sqlLock);

Open in new window

This issue was the []
 I'm a pretty seasoned vet with Access, and i know about the #'s for dates, just wasn;t sure if it used them when useing PHP to do the call.
 
Hey what about me! :(
Did my script not work?
No, youres didn't work because of the ' around then TimeStamp.
 $sqlLock = "UPDATE ".$tblNameLock." SET Lock = 'Y', TimeStamp = '".$TimeStmp."' WHERE Conc='".$FC."'";

and no brackets around the field names. Which is what the real issue was.
Hey thanks for the follow up I just wanted to make sure :)
I've been burned by both Date/Time formatting issues and the square brackets bit (the technical name escapes me) too many times to count...

the scars run deep...I still wake up in the night sometimes, screaming...

...but I digress.

Apologies if I came off snotty or anything in my response, twas not my intention.

Take Care,

ELCM