SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: human date to timestamp
-
Nov 19, 2008, 09:21 #1
- Join Date
- Jan 2005
- Location
- blahblahblah
- Posts
- 1,447
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
human date to timestamp
Hi,
I-ve got this date:
19.11.2008 09:00:16
Is it possible to turn it into a timestapm that I could store in a db?
Thanks in advance
Regards,
-jj.
-
Nov 19, 2008, 09:42 #2
- Join Date
- Sep 2006
- Location
- Nottingham, UK
- Posts
- 3,133
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
http://uk3.php.net/manual/en/function.strtotime.php
or, you could use a regular expression. I don't entirely trust functions that say 'give me something and ill try and output something useful!' - I like it's behaviour to be well defined, so I know what I can expect given different inputs!
-
Nov 19, 2008, 10:25 #3
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
you could also pass that string directly into mysql and use its STR_TO_DATE function to make a valid DATETIME value, or use STR_TO_DATE nested inside the UNIX_TIMESTAMP function to turn it into a unix epoch integer
you did not really say whether you wanted to store a datetime value or a "timestamp" value (which many people interpret as being the unix epoch timestamp)
-
Nov 19, 2008, 10:26 #4
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$date = '19.11.2008 09:00:16';
list($date, $time) = split(' ', $date);
list($d, $m, $y) = split('\.', $date);
$timestamp = strtotime("$y-$m-$d $time");
echo date('Y-m-d H:i:s', $timestamp);
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
Bookmarks