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);
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 -.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Access Date/Time Format Example =
#5/12/95 6:00:00AM#
#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);
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);
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);
ASKER
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.
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?
ASKER
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.
$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
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
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:
Open in new window