republican-creole
Search:  

 
 
   All ForumsHot TopicsGallery






how-to block ads


 
Forums » Tech and Talk » OS and Software » Webmasters and Developers » date string to Unix_Timestamp syntax
Search Topic:
Uniqs:
290
Share Topic:
RSS topic:
toggle:
flat / full
normal / watch
Posting:
Post a:
Post a:
Drupal question »
« javascript onclick  
AuthorAll Replies


Johnny
Premium
join:2001-06-27
Atlanta, GA
·Comcast

date string to Unix_Timestamp syntax

Hey,

I wound up with a date-time string in mySQL column, and I've been trying to just convert it to an integer Unix timestamp. I tried several of the PHP functions but none did a a simple conversion.

So

1. Is there in fact a PHP function that will just take another PHP variable (say $datetime that has its value "2009-10-31 12:40:50") and return an integer that is the Unix_Timestamp?

2. Failing that, I tried to make a calculated column in my MySQL DB by the following:

$query = "INSERT INTO Feedbacks (datetimestring, unixtimestamp) VALUES ('$datetimestring', 'UNIX_TIMESTAMP('$datetimestring')')";

Can somebody clue me in on how to get Unix timestamp from this string? I'd prefer to just calculate it in PHP rather than store it in the database, but either will do.

NOTE: I'm sure people are curious why I convert to string and then back to a timestamp. It's because the original date came in big-endian.


ekiM
Oh Well

join:2001-01-06
/usr/home
clubs:
How about strtotime() ?


twizlar
I dont think so.
Premium
join:2003-12-24
Brantford, ON

reply to Johnny
I would probably just use UNIX_TIMESTAMP when you are pulling the data from mysql.


--
Broadline Networks Inc.


Johnny
Premium
join:2001-06-27
Atlanta, GA
·Comcast

reply to ekiM
said by ekiM See Profile :

How about strtotime() ?
I tried that, but it says it returns it relative to either a supplied timestamp or to the current time.

The function expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now , or the current time if now is not supplied.
So that was confusing, since I don't want it relative to anything - just a simple conversion to integer so I can compare it to another timestamp in another table.


GILXA1226
Premium,MVM
join:2000-12-29
London, OH
clubs:

said by Johnny See Profile :

said by ekiM See Profile :

How about strtotime() ?
I tried that, but it says it returns it relative to either a supplied timestamp or to the current time.

The function expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now , or the current time if now is not supplied.
So that was confusing, since I don't want it relative to anything - just a simple conversion to integer so I can compare it to another timestamp in another table.
Why not just pass it January 1 1970 for the relative date?
--
We don't give a d@mn for the whole state of Michigan... we're from OHIO! O!H! ... I!O!


Johnny
Premium
join:2001-06-27
Atlanta, GA
·Comcast

I'll give that a shot - seems like a hack though.

I kludged another way, converting the 4 bytes of the network-order stream I receive into a hex string and then back to decimal. Somehow in that process, the endianness gets set to little-endian.

Now it's just a matter of which is the better hack.


GILXA1226
Premium,MVM
join:2000-12-29
London, OH
clubs:

said by Johnny See Profile :

I'll give that a shot - seems like a hack though.

I kludged another way, converting the 4 bytes of the network-order stream I receive into a hex string and then back to decimal. Somehow in that process, the endianness gets set to little-endian.

Now it's just a matter of which is the better hack.
What type of system is the data coming from and going to? Those conversions should not be changing the endian ness of the data unless something is being converted in a strange way.
--
We don't give a d@mn for the whole state of Michigan... we're from OHIO! O!H! ... I!O!


Johnny
Premium
join:2001-06-27
Atlanta, GA
·Comcast

said by GILXA1226 See Profile :

said by Johnny See Profile :

I'll give that a shot - seems like a hack though.

I kludged another way, converting the 4 bytes of the network-order stream I receive into a hex string and then back to decimal. Somehow in that process, the endianness gets set to little-endian.

Now it's just a matter of which is the better hack.
What type of system is the data coming from and going to? Those conversions should not be changing the endian ness of the data unless something is being converted in a strange way.
Well this is the big question. I do an fread() in a loop to get 38 bytes of binary data at a time until there is no more. Apple says (see below) that the first 4 bytes are a Unix timestamp in "network order" (big endian). Intel servers, like my Linux/PHP/MySQL/Apache server on which I am running this script, use little-endian order. In fact, all of the Objective-C utilities which read this stream reverse the byte order as they receive it. What I could not find out is whether PHP knows to do this or not.

Each of these 38-byte items is defined by Apple as:

Begin reading the stream written by the feedback service until there is no more data to read. The received data is in tuples having the following format:
Figure 4-2 Binary format of a feedback tuple



time_t
A timestamp (as a four-byte time_t value) indicating when the APNs determined that the application no longer exists on the device. This value, which is in network order, represents the seconds since 1970, anchored to UTC.
You should use the timestamp to determine if the application on the device re-registered with your service since the moment the device token was recorded on the feedback service. If it hasn’t, you should cease sending push notifications to the device.

token length
The length of the device token as a two-byte integer value in network order.

device token
The device token in binary format.


cowboyro

join:2000-10-11
Shelton, CT
·AT&T U-Verse
·Comcast
·Optimum Voice


1 edit
reply to Johnny
strtotime()




cowboyro

join:2000-10-11
Shelton, CT
reply to Johnny
Or straight into mysql:
'November 3rd, 2009 05:10:05PM'


Johnny
Premium
join:2001-06-27
Atlanta, GA
reply to cowboyro
Looks good. I wonder why it says that it offsets it relative to the current time?
-
Forums » Tech and Talk » OS and Software » Webmasters and DevelopersDrupal question »
« javascript onclick  


Tuesday, 15-Dec 06:13:54 Terms of Use | Privacy Policy | Hosting by www.nac.net - DSL,Hosting & Co-lo | feedback | contact
over 10 years online! © 1999-2009 dslreports.com.republican-creole
page compression OFF
Most commented news this week
· [146] Verizon Kindly Forgives Kid's $21,917 3G Bandwidth Bill
· [103] Google To Sell Phone Directly To Consumers
· [73] TiVO Tries To Figure Out Where It Fits
· [55] Faster Verizon DSL Service Will Burn Your House Down
· [48] NY Times: AT&T 3G Network Is Secretly Awesome
· [32] Rural Broadband User? You're Screwed
· [26] Can Satire Take Down AT&T's 3G Network?
· [24] Sweden First To Get LTE Service
· [7] Monday Evening Links
· [1] Monday Morning Links
Most people now reading
· Windows 7 boot manager editing questions [Microsoft Help]
· Official Mediacom Email Discussion Thread [Mediacom]
· personal check etiquette [General Questions]
· Ashen Verdict Rep farming guide (ICC 10) [World of Warcraft]
· IMG 1.7 (IMG Updates and Discussion) [Verizon FIOS TV]
· 3.x Feral Druid - Bear Tanking Guide [World of Warcraft]
· Lady Deathwhisper Strategy - 3.3 Live [World of Warcraft]
· persistent connection to qw-in-f113.1e100.net on boot [Security]
· What frequency is better for a 25+ mile link [Wireless Service Providers]
· Opening a file download dialog from a JavaScript function. [Webmasters and Developers]