473,842 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

negative time() ?

I need to store a date prior to the unix epoch, any pointers?
--

Rick

Digital Printing
www.intelligence-direct.com
Jul 17 '05 #1
12 3690
Rick <ri**@intellige nce-direct.com> wrote:
I need to store a date prior to the unix epoch, any pointers?


Store! Where are you storing the time?

<q src='http://nl3.php.net/manual/en/function.date.p hp'>
Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901
20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that
correspond to the minimum and maximum values for a 32-bit signed
integer). On Windows this range is limited from 01-01-1970 to
19-01-2038.
</q>

So what platform are you on?

--

Daniel Tryba

Jul 17 '05 #2
Rick wrote:
I need to store a date prior to the unix epoch, any pointers?


php$ cat olddate.php
<?php
$Neil_Armstrong _lunar_landing = -14245424;

echo gmdate('r', $Neil_Armstrong _lunar_landing) , "\n";
?>

php$ php olddate.php
Sun, 20 Jul 1969 02:56:16 +0000

So ... just store the number of seconds *before* unix epoch.

--
USENET would be a better place if everybody read:
http://www.expita.com/nomime.html
http://www.netmeister.org/news/learn2quote2.html
http://www.catb.org/~esr/faqs/smart-questions.html
Jul 17 '05 #3
Daniel Tryba wrote:
So what platform are you on?


Well, after you both pointed out there should be no problem with negative
time on linux I had a poke around and it seems to be a problem with a
function I am using to convert a Mysql datetime to a number. Forget where I
got it from, probably from the php.net documentation comments (will teach
me for being lazy)

Feed it a date prior to to '1970-01-01 00:00:00' (such as '1946-06-07
19:29:04') and it returns -1

function datetime_to_tim e($datetime) {
$date_time = split("\040",$d atetime);
$date = split("-",$date_tim e[0]);
$time = split(":",$date _time[1]);
return mktime($time[0],$time[1],$time[2],$date[1],$date[2],$date[0]);
}
--

Rick

Digital Printing
www.intelligence-direct.com
Jul 17 '05 #4
Rick wrote:
Feed [mktime()] a date prior to to '1970-01-01 00:00:00' (such as
'1946-06-07 19:29:04') and it returns -1

function datetime_to_tim e($datetime) {
$date_time = split("\040",$d atetime);
$date = split("-",$date_tim e[0]);
$time = split(":",$date _time[1]);
return mktime($time[0],$time[1],$time[2],$date[1],$date[2],$date[0]);
}


MySQL 4.1.1 has the function datediff() which I can't test right now.

http://dev.mysql.com/doc/mysql/en/Da...functions.html
Maybe this works:

SQL> select datediff('1946-06-07', '1970-01-01');

And you'll get the *negative* number of days till unix epoch; multiply
that by 86400 (seconds in a day) and you get a *negative* unix
timestamp that hopefully you can use directly in PHP.

--
USENET would be a better place if everybody read:
http://www.expita.com/nomime.html
http://www.netmeister.org/news/learn2quote2.html
http://www.catb.org/~esr/faqs/smart-questions.html
Jul 17 '05 #5
.oO(Rick)
I need to store a date prior to the unix epoch, any pointers?


Use ISO-format: YYYY-MM-DD HH:MM:SS

Micha
Jul 17 '05 #6
Michael Fesser wrote:
Use ISO-format: YYYY-MM-DD HH:MM:SS


That isn't a representation specified by ISO8601, although
it closely resembles one and might be less odd looking to
some people than any standard representation. On his page
(see http://www.cs.tut.fi/~jkorpela/iso8601.html ), Jukka
Korpela mentions that 'people who otherwise use ISO 8601
might deviate from it here by using a space', as you did
above; but note that he recommends a combined date and time
of the day representation that strictly abides by ISO8601.

The standard clearly states that spaces are not used in its
representations (sec. 4.4). More, the time designator ('T')
may be omitted only by agreement between the parties
involved, where the date and time of the day representation
is unambiguous.

The complete, extended (that is, including separators)
representation of a calendar date* and local time of the day
is (contained in square brackets): [YYYY-MM-DDThh:mm:ss].
If readability comes second to compression though, the
basic format (that is, excluding separators) can be used:
[YYYYMMDDThhmmss].

Of course a local time itself may not always be appropriate.
To instead express a UTC time, append the UTC designator
('Z') to the time representation: [YYYY-MM-DDThh:mm:ssZ].
To express the difference between local time and UTC, append
to the time representation [±hh:mm] (extended format),
[±hhmm] (basic format), or [±hh] if the difference is an
integral number of hours. [hh] and [mm] indicate the
difference in hours and minutes respectively: e.g. [2004-10-
21T20:28:30+01: 00] was when I composed this article; that
is, Thu, 21 Oct 2004 19:28:30 GMT.

There's more to it. If you have time, read

http://hydracen.com/dx/iso8601.htm
* Besides calendar dates, where the day is identified by the
day of the month of the year, the standard also specifies
representations for ordinal dates, where the day is
identified by the day of the year; and week dates, where the
day is identified by the day of the week of the year.

HAGW!

--
Jock
Jul 17 '05 #7
Michael Fesser wrote:
.oO(Rick)

I need to store a date prior to the unix epoch, any pointers?

Use ISO-format: YYYY-MM-DD HH:MM:SS

Micha

Hi,

We allways store date, time and timestamp in MySql using ISO format.
There is no problem as long as you do not want to convert them to an
integer like used by time(). See
http://www.phppeanuts.org/examples/e...?pntType=Hours
for a working example.

The framework can also convert dates like these to simple european
dates, and back, see
http://www.phppeanuts.org/examples/e...?pntType=Hours
(The user interface converts the dates. In de domain objects and the
database ISO format is used. The class StringConverter and its
superclass that does the actual conversions should work without the rest
of the framework. Same for ValueValidator to do Validations (minimum and
maximum values and lengths). If there is a demand for it we will make
these classes available as a separate download (nobody asked of it yet).

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

Jul 17 '05 #8
Henk Verhoeven <ne***@phppeanu tsremove-this.org> wrote:
Use ISO-format: YYYY-MM-DD HH:MM:SS


We allways store date, time and timestamp in MySql using ISO format.
There is no problem as long as you do not want to convert them to an
integer like used by time(). See
http://www.phppeanuts.org/examples/e...?pntType=Hours
for a working example.


That sound terribly inefficient. Why not use that databses date/time
format? Then there are no limits to converting also.

--

Daniel Tryba

Jul 17 '05 #9
.oO(John Dunlop)
Michael Fesser wrote:
Use ISO-format: YYYY-MM-DD HH:MM:SS


That isn't a representation specified by ISO8601, although
it closely resembles one and might be less odd looking to
some people than any standard representation. [...]


OK, what I had in mind were the native SQL types DATE, TIME and
TIMESTAMP, which use the above format. So it's at least ISO 9075. ;)

Micha
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2158
by: dan | last post by:
I was recently surprised, and quite shocked in fact, to find that Python treats negative indices into sequence types as if they were mod(length-of-sequence), at least up to -len(seq). This fact is *deeply* buried in the docs, and is not at all intuitive. One of the big advantages of a high-level language such as Python is the ability to provide run-time bounds checking on array-type constructs. To achieve this I will now have to...
7
10327
by: Colin Brown | last post by:
Python 2.3.3 Under Windows NT: Negative Int or Real -> sleeps for a long time Under Linux: Returns IOError: Invalid argument I consider both of these unfriendly results and expected the preferable silent time.sleep(0) in much the same way that slicing a string beyond the ends returns an empty string. Colin Brown PyNZ
19
5175
by: Imbaud Pierre | last post by:
integer division and modulo gives different results in c and python, when negative numbers are involved. take gdb as a widely available c interpreter print -2 /3 0 for c, -1 for python. more amazing, modulos of negative number give negative values! (in c). from an algebraic point of view, python seems right, but I thought python conformity to the underlying c compiler was a strong commitment, obviously not here, and I found no...
1
1961
by: Tom Mortimer | last post by:
Hi, A quick question - can anyone tell me how to interpret negative time values in pstats.Stats.print_stats() output? Eg - 39052965 function calls (38035317 primitive calls) in -250.959 CPU seconds Ordered by: internal time
16
5098
by: JKop | last post by:
Take a class like the following: class Finger { public: double length; }
13
6551
by: Ron | last post by:
Hi all I'm deciding whether to use the PK also as an account number, invoice number, transaction number, etc that the user will see for the respective files. I understand that sometimes a number will be missing, which is not a problem for my purposes I don't think, but how would it be negative? Can randomly created PK autonumber fields be negative? Any way for a PK, autonumbered, *incremented* to be negative? TIA
11
11958
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not figure out how to reply to the thread per se using Google Groups and so please forgive me for cutting and pasting (I emailed him but he may not have time to check his email), and I am hoping someone might be able to tell me how I can change this...
15
35533
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
39
4035
by: Frederick Gotham | last post by:
I have a general idea about how negative number systems work, but I'd appreciate some clarification if anyone would be willing to help me. Let's assume we're working with an 8-Bit signed integer, and that it contains no padding. Firstly, I realise that the MSB is known as the sign-bit, and that it indicates whether the number is positive or negative (irrespective of which negative number system is used).
0
9875
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9715
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10614
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10317
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7859
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7040
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5697
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4500
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3146
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.