473,756 Members | 6,482 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php/mysql date

63 New Member
hi,
I have some problems related to date type:
In mysql, I created a table with some fields of date type, so how can I use php to insert date value in into database (then db will store date format, instead of breaking it into separate smaller attributes: date, month, year...with int type like i did before- I don't like it)

Then when I call out these value, how can I perform calculation (in php, of course). For example: how many days from 13/3/08 to 31/4/08 or from 20/5/2008 to 10/6/2008

thanks
May 6 '08 #1
4 2167
rpnew
188 New Member
hi,
I have some problems related to date type:
In mysql, I created a table with some fields of date type, so how can I use php to insert date value in into database (then db will store date format, instead of breaking it into separate smaller attributes: date, month, year...with int type like i did before- I don't like it)

Then when I call out these value, how can I perform calculation (in php, of course). For example: how many days from 13/3/08 to 31/4/08 or from 20/5/2008 to 10/6/2008

thanks
Hi,
There is datatype date and datetime in MySql in which you can store your date and date with timestamp respectively. So you can define that column in database and using date function in PHP you can insert it into database.

Not much sure about calculation regarding dates...

Regards,
RP
May 6 '08 #2
ronverdonk
4,258 Recognized Expert Specialist
When possible try to calculate the date and time differences in your MySQL select, there are many functions in MySQL that allow that.

Is it really necessary to calculate these values in PHP, i.e. outside MySQL?

Ronald
May 6 '08 #3
tuananh87vn
63 New Member
I've found way to insert and print out the date-type data in 'date-month-year' (insead of 'Year-month-date' form in mysql) by using strtotime()func tion, however still dont know how to subtract two dates.

Hmm, actually I may not care whether it's done inside or outside mySQL. Given a case that I insert job information into database, which includes add_date and expire_date. so I need to calculate the substraction of the two date, then when the result is equal or greater than 0 (i.e the job is expired) then the job status will change from available to expired. If this can hardly be done in php so how to do it in form of sql query then using php's mysql_query() to run it.

The 2nd case is that when a user logs out of a system, that moment will be stored in db as last login time, and now I want to query all the jobs which are added from the last login time until the moment the user logs in again (i.e all new added jobs). Can it be like "SELECT * FROM job_table WHERE add_date > lastlogin AND add_date <= $now" or else?
May 9 '08 #4
rpnew
188 New Member
I've found way to insert and print out the date-type data in 'date-month-year' (insead of 'Year-month-date' form in mysql) by using strtotime()func tion, however still dont know how to subtract two dates.

Hmm, actually I may not care whether it's done inside or outside mySQL. Given a case that I insert job information into database, which includes add_date and expire_date. so I need to calculate the substraction of the two date, then when the result is equal or greater than 0 (i.e the job is expired) then the job status will change from available to expired. If this can hardly be done in php so how to do it in form of sql query then using php's mysql_query() to run it.

The 2nd case is that when a user logs out of a system, that moment will be stored in db as last login time, and now I want to query all the jobs which are added from the last login time until the moment the user logs in again (i.e all new added jobs). Can it be like "SELECT * FROM job_table WHERE add_date > lastlogin AND add_date <= $now" or else?
Hi,
You can use following...
Expand|Select|Wrap|Line Numbers
  1. select * from table where date between start_date and end_date;
  2.  
Some formating might be needed with date.. not sure though..

Regards,
RP
May 9 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4425
by: Neil | last post by:
Hi, I hope this question isn't too far off topic....I'm almost at my wits end trying to figure this out. I have a Mysql database and I wish to automate the backup of the database because I don't wish to rely on the web host doing so. I am using the "dbsender.php" script, which is written for this exact purpose (available at hotscripts.com). If I execute the script via my browser, the database is emailed to me in a 'gzip' format, which...
3
2242
by: Mark Stevens | last post by:
I am trying to do select all of the records in a table where they data has not expired. The table contains two fields Subject (varchar(100)) and ExpiryDate (Date). I am getting all of the records returned when I execute: $sql = "select * from tbl where ExpiryDate > " . date("Y-m-d"); mysql_query($sql);
4
7082
by: RT | last post by:
If anyone can help that would be great. I¹m trying to format a timestamp from my MySQL table (sessions) Here¹s the code I¹m using: <?php echo date('D,n-j-y h:i:s a',strtotime($row_rsSessions)); ?> If I give the timestamp a value of 8 I can get the date to work correctly
0
1680
by: David Bordas | last post by:
Hi list, I've got a little bug with MySQL. I can insert a row into my table but this row will not appear in the table :( Server is under linux redhat, MySQL is 3.23.56 installed from binary tar.gz from MySQL team. Table Description : mysql> desc Log_Forums;
0
2691
by: Philip Stoev | last post by:
Hi all, Please tell me if any of this makes sense. Any pointers to relevant projects/articles will be much appreciated. Philip Stoev http://www.stoev.org/pivot/manifest.htm ===================================
1
7192
by: windandwaves | last post by:
Hi Folk Some of you may be interested in a function that allows you to add/substract from a date in PHP, using a MySql Dateformat (e.g. 2005-10-31) (NOT TESTED): Any comments appreciated. <?php /*
4
3333
by: Dan Lewis | last post by:
I've imported a ms access database into a table in a mysql database. The access database contains a field that holds date/time values in 'general date' format. These all show up at 01/01/1970 in the mysql database. I believe the field in mysql is wanting UTC and shows numbers when looked at from the sql command line (i.e. March 13, 2006, 5:31 pm is shown as 1142289086). How do I get the access data into that format so it will import...
12
4444
by: mantrid | last post by:
Hello Can anyone point me in the right direction for the way to read a text file a line at a time and separate the fields on that line and use them as data in an INSERT to add a record to a mysql table. Then read the second line in text file and repeat. Thanks for your time Ian
1
2526
by: paulq182 | last post by:
PLEASE HELP ME WITH MY CODE?? import java.sql.*; import java.io.*; class min_filmdb_rel_mysql { public static void main (String args ) throws SQLException, IOException {
6
38518
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get through this without much trouble. Programming knowledge is not required. Index What is SQL? Why MySQL? Installing MySQL. Using the MySQL command line interface
0
9462
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
9287
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,...
1
9857
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,...
0
9722
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...
0
8723
agi2029
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...
1
7259
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
6542
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
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3817
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 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.