Reputation: 110203
I need to write to a file and then get the last_modified date and update a table.
How would I do the following:
echo 'new file' > /tmp/file.txt
stat /tmp/file.txt
16777218 16641883 -rw-r--r-- 1 david wheel 0 6 "Feb 19 16:48:21 2013"
"Feb 19 16:48:21 2013" "Feb 19 16:48:21 2013" "Feb 19 16:48:21 2013"
4096 8 0 hello.txt
How would I get the last_modified time in the format of "YYYY-MM-DD HH:MM:SS"
to do the following SQL update?
update title set datetime='2012-01-01 00:00:01' where id=2
Upvotes: 1
Views: 590
Reputation: 444
As you are using bash, it's precised in the man page that you can display your result in a specific format, so you can precise stat to print the result with a human readable time format.
stat --format=%x your_file
will display the time of last access.
Now the output format can depend on the shell you are using, (as stat can be a builtin), so if you want to be sure to get it parsed as you want to, you can use the uppercase option letter, which will give you the lowercase letter option result, in Epoch format.
So that if you create a little program that can take in entry an Epoch time and prints out the human readable time you want to get, you could do:
cat --format=%X your_file | ./your_epoch_translator_program > your_result_file
update tile set datetime=`cat your_result_file` where id=2
That's just an idea, hope this helps !
Upvotes: 1