What do you think is the best way to store Dates into a database ?
If you want to keep logs or buckups....
I am using date('dmYHis')
but I doesn't work really well ...
Is it better to use date(U) ?
Any suggestions ?
And if you can let me know how you can Display that date back in the Screen
!
Thanks 8 1763
Angelos wrote: What do you think is the best way to store Dates into a database ? If you want to keep logs or buckups....
I am using date('dmYHis') but I doesn't work really well ... Is it better to use date(U) ? Any suggestions ?
Use the date or datetime field type - the exact name of the type depends
on your DBMS.
And if you can let me know how you can Display that date back in the Screen !
Depending which DBMS you are using there may be a function for
formatting the date; in MySQL for example you would use the
date_format() function.
Otherwise you can use the PHP function strtotime() to change it to a
timestamp and then date() to format it as you wish. The downside with
this is you are limited to the range of a unix timestamp which is from
1970 to 2038.
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Hi
The best way that I found is to use
$date = date("Y-m-d H:i:s");
Works with mysql within a datetime field..
For a date field use date("Y-m-d") and for a time field use date("H:i:s")
Regards
Ray
"Angelos" <an*****@redcat media.net> wrote in message
news:d8******** **@nwrdmz02.dmz .ncs.ea.ibs-infra.bt.com... What do you think is the best way to store Dates into a database ? If you want to keep logs or buckups....
I am using date('dmYHis') but I doesn't work really well ... Is it better to use date(U) ?
Any suggestions ?
And if you can let me know how you can Display that date back in the Screen !
Thanks
Chris Hope wrote: Angelos wrote:
What do you think is the best way to store Dates into a database ? If you want to keep logs or buckups....
Use the date or datetime field type - the exact name of the type depends on your DBMS.
Good advice.
Otherwise you can use the PHP function strtotime() to change it to a timestamp and then date() to format it as you wish. The downside with this is you are limited to the range of a unix timestamp which is from 1970 to 2038.
strtotime() is very american in its interpretation of dates. Also Unix
timestamps are a bad way to store dates - even if you are running on a 64
bit system (i.e. can work with timestamps after 2036, which isn't so far
away now) you can't work with timestamps before 1970.
HTH
C.
Colin McKinnon <co************ **@andthis.mms3 .com> wrote: strtotime() is very american in its interpretation of dates. Also Unix timestamps are a bad way to store dates - even if you are running on a 64 bit system (i.e. can work with timestamps after 2036, which isn't so far away now) you can't work with timestamps before 1970.
$ touch -t 191204140000 foo
$ ls -la foo
-rw-r--r-- 1 me me 0 Apr 14 1912 foo
$ stat foo
File: `foo'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: eh/14d Inode: 20099 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 491/ me) Gid: ( 491/ me)
Access: 1912-04-14 00:00:00.000000 000 +0019
Modify: 1912-04-14 00:00:00.000000 000 +0019
Change: 2005-06-16 16:19:20.000000 000 +0200
$ stat -c %X foo
-1821399572
$ php4
<?php
echo date('r',-1821399572);
echo "\n";
?>
Sun, 14 Apr 1912 00:00:00 +0019
$
What do I have here.... a negative unix timestamp... IMHO on most systems
time_t is signed.
The biggest problem is that it is 32bit on most systems.
> Use the date or datetime field type - the exact name of the type depends on your DBMS.
And if you can let me know how you can Display that date back in the Screen !
OK so I am using MySQL and I store it in a DATETIME datatype in the MySQL DB
in the folowing format :
$date = date("YmdHis");
So how you would display that ?
Is teh folowing correct ?
date('d M Y',strtotime(ro w['log_date']))
"Chris Hope" <bl*******@elec trictoolbox.com > wrote in message
news:d8******** **@lust.ihug.co .nz... Angelos wrote:
What do you think is the best way to store Dates into a database ? If you want to keep logs or buckups....
I am using date('dmYHis') but I doesn't work really well ... Is it better to use date(U) ? Any suggestions ?
Use the date or datetime field type - the exact name of the type depends on your DBMS.
And if you can let me know how you can Display that date back in the Screen !
Depending which DBMS you are using there may be a function for formatting the date; in MySQL for example you would use the date_format() function.
Otherwise you can use the PHP function strtotime() to change it to a timestamp and then date() to format it as you wish. The downside with this is you are limited to the range of a unix timestamp which is from 1970 to 2038.
I don't recall date() being limited -
I often use something like $today = date('Y-m-d'); to get a date to enter
into a MySQL database. And when I have a date value that needs translating,
I just use string concatenation: $otherdate = $year . '-' . $month . '-' .
$day; (assuming $year, $month, and $day are numeric, of course)
Tony wrote: "Chris Hope" <bl*******@elec trictoolbox.com > wrote in message news:d8******** **@lust.ihug.co .nz... Angelos wrote:
What do you think is the best way to store Dates into a database ? If you want to keep logs or buckups....
I am using date('dmYHis') but I doesn't work really well ... Is it better to use date(U) ? Any suggestions ?
Use the date or datetime field type - the exact name of the type depends on your DBMS.
And if you can let me know how you can Display that date back in the Screen !
Depending which DBMS you are using there may be a function for formatting the date; in MySQL for example you would use the date_format() function.
Otherwise you can use the PHP function strtotime() to change it to a timestamp and then date() to format it as you wish. The downside with this is you are limited to the range of a unix timestamp which is from 1970 to 2038.
I don't recall date() being limited -
I often use something like $today = date('Y-m-d'); to get a date to enter into a MySQL database. And when I have a date value that needs translating, I just use string concatenation: $otherdate = $year . '-' . $month . '-' . $day; (assuming $year, $month, and $day are numeric, of course)
date() isn't. strtotime() is as it returns a unix timestamp.
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Colin McKinnon wrote: Chris Hope wrote:
Angelos wrote:
What do you think is the best way to store Dates into a database ? If you want to keep logs or buckups....
Use the date or datetime field type - the exact name of the type depends on your DBMS. Good advice.
Otherwise you can use the PHP function strtotime() to change it to a timestamp and then date() to format it as you wish. The downside with this is you are limited to the range of a unix timestamp which is from 1970 to 2038.
strtotime() is very american in its interpretation of dates. Also Unix timestamps are a bad way to store dates - even if you are running on a 64 bit system (i.e. can work with timestamps after 2036, which isn't so far away now) you can't work with timestamps before 1970.
Hence my note about the downside :)
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robert |
last post by:
I have no problem storing dates + times in a
System.DateTime object. In addition, it's easy to output
a Time as a string from an existing Date/Time. But I'm
having trouble storing a time only. Is there any way to
store only a time without the date portion (like 3:00 am)
in this data structure? Or, if not, is there another
data structure that would be preferable?
Thanks
|
by: Thomas R. Hummel |
last post by:
Hello all,
I have been working with several databases here that are basically data
marts. A lot of the entities have an attribute that is a particular
year and month. For example, a financial transaction may be posted for
a particular month, regardless of the actual date on which it occurred.
In this system, these year/month combinations have typically been
stored as integers of the form YYYYMM. My question is, how have others
stored...
|
by: Zvonko |
last post by:
Hi!
I would like to get the clients date and time (his system time) and
store it somewhere so I can use it in my code later. (insert it to
database!).
Any ideas
Zvonko
|
by: dd_bdlm |
last post by:
Hi all
I have a database that stores customer records and their associated
insurance details. I need to be able to track any changes made to that
record within a set time period ie if details are changed fine it is
reported next time report is run. But if details are changed more than
once in between reports then first detail change is lost.
I would like to work out a way that changes can be written to a
??seperate version of the...
|
by: IntraRELY |
last post by:
Here is my code, but get errors:
Dim installment = 1
Dim beginDate = "1/1/03"
Dim endDate = "1/1/08"
Dim dates(5) As Array
While installment <= 5
endDate = DateAdd(DateInterval.Year, 1, beginDate)
dates.SetValue(couponEndDate, installment)
installment = installment + 1
| |
by: fauxanadu |
last post by:
Is it possible to store dates before 01/01/0100 A.D. (such as for as database storing world events would require) using MS Access?
Verbose Explination
I need to be able to store dates before 100CE in a date field. This is for a world history database that I am building. I am currently storing dates in a database as unformatted text (14 characters: mm/dd/yyyy/. This requires using alot of extra VBA code to validate the dates to ensure...
|
by: billelev |
last post by:
Hi there,
Does anyone know how to store a constant in VBA that is set using a function or sub-routine?
Here is the scenario. When I load up Access for the first time, I'd like to calculate the previous business day and month end. This only really needs to be done once, as both dates are 'constant' for that session. I would like to calculate the dates, and assign them to some kind of variable.
The problem is that VBA will not allow...
|
by: nightscorpion |
last post by:
Hello everyone.
i have 2 dates given
FromDate :1998-04-13T00:00:00
ToDate :1998-04-18T23:59:00
i would like to store these two days as single dates in the table in my db
could anyone suggest me how to store single dates in the db?
ie
FromDate :1998-04-13T00:00:00
|
by: John A Grandy |
last post by:
What are some best practices for storing pure dates and pure times in .NET ?
I notice that DateTime.TimeOfDay() returns type TimeSpan , which is
certainly sufficient for storing pure times , but not constrained ...
Do people write their own classes ? Or have I overlooked one or more
intrinsic .NET classes ?
|
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...
|
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,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |