Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by ats2012
at 2024-02-17 08:04:27
Point:500 Replies:5 POST_ID:828888USER_ID:11790
Topic:
PHP Scripting Language;;
I setup a php script to pull the date modified date of a file and insert it into a database. When I run this script from a website the date comes back with the correct date. When I run it from Windows Scheduled task it come back with the incorrect date. Below is the script:
<?php$con = mysql_connect('host','user','pass');if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("ats", $con);mysql_query('TRUNCATE TABLE timeoff_file_date') or die(mysql_error()); $filename = 'E:wampwww imeoff imeoff_dataLawson.TimeAccrual.csv';if (file_exists($filename)) { $date_modified = date ("Y-m-d H:i:s", filemtime($filename)); echo $date_modified; $import_date = "INSERT INTO timeoff_file_date VALUES('".$date_modified."')"; mysql_query($import_date) or die(mysql_error());}fclose($fp);mysql_close($con);echo "File Imported";?> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:
Expert: duncanb7 replied at 2024-02-17 10:34:15
Thanks your pt and have a nice day
Duncan
Duncan
Expert: Ray Paseur replied at 2024-02-17 10:25:22
Great! Thanks for using EE, ~Ray
Author: ats2012 replied at 2024-02-17 10:17:09
Added date_default_timezone_set('America/Chicago'); and it worked.
Thanks
Thanks
Assisted Solution
Expert: Ray Paseur replied at 2024-02-17 10:02:14
250 points EXCELLENT
PHP and MySQL have different dates, independent with no locking between them. PHP uses a "timezone" to format the Unix Timestamp for local use. If this is set incorrectly (or the system date is off) you may get faulty results. This article explains the theory and practice:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
You might also want to have an else clause for the if() statement on line 13.
And in unrelated, but important news, PHP is doing away with MySQL support. The extension was deprecated at PHP 5.5, which is current. An article that will help you map the familiar but obsolete MySQL functions to MySQLi or PDO is available here:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
You might also want to have an else clause for the if() statement on line 13.
And in unrelated, but important news, PHP is doing away with MySQL support. The extension was deprecated at PHP 5.5, which is current. An article that will help you map the familiar but obsolete MySQL functions to MySQLi or PDO is available here:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
Accepted Solution
Expert: duncanb7 replied at 2024-02-17 09:03:27
250 points EXCELLENT
When I run this script from a website the date comes back with the correct date
Do you know what is system linux or window on the website you got correct date ?
if it is linux , the date() might output the different from window.
http://hk2.php.net/function.date
The manual on date() points out two differences:
Timestamps used to range from 1970 to 2038 on Windows before PHP 5.1.0.
According to a User Contributed Comment, the Microseconds switch can't be used on Windows.
If the issue is not from system difference between linux and window, could you try
put date_default_timezone_set('yourtimezone') in your script and test it again on
website and window schedule ? where yourtimezone you can find in
php.net.
Hope understand your question completely, if not please pt it out.
Duncan