Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

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

0
LostTime
Asked:
LostTime
  • 7
  • 3
  • 3
1 Solution
 
EverLearningCodeMonkeyCommented:
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

0
 
LostTimeAuthor Commented:
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 -.
0
 
EverLearningCodeMonkeyCommented:
Having been through a fair share of pain and suffering with access I'm pretty sure that the # is the way dates are delimited.  Though I've been wrong before.

Something that might be worth trying, is to make sure your field and table names have have square brackets around them, just in case any of the names you're using conflict with any predefined terms - Access used to cough on things like that too.

You might want to try getting just a date to work and then phasing in time to see where the date part is breaking down.  I don't think Access will actually track microseconds so you may just want to drop that all together, or at least wait until date & time are properly saving.  Usually I've found that access wants things in a mm/dd/yyyy format.


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
NerdsOfTechTechnology ScientistCommented:
Access Date/Time Format Example =

#5/12/95 6:00:00AM#
0
 
NerdsOfTechTechnology ScientistCommented:
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

0
 
NerdsOfTechTechnology ScientistCommented:
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

0
 
NerdsOfTechTechnology ScientistCommented:
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

0
 
LostTimeAuthor Commented:
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.
 
0
 
NerdsOfTechTechnology ScientistCommented:
Hey what about me! :(
0
 
NerdsOfTechTechnology ScientistCommented:
Did my script not work?
0
 
LostTimeAuthor Commented:
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.
0
 
NerdsOfTechTechnology ScientistCommented:
Hey thanks for the follow up I just wanted to make sure :)
0
 
EverLearningCodeMonkeyCommented:
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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now