Is there any way to increase a table field named month every month..or I should say to the latest month...Just need to update the month value..i.e. In, it should be 1
march 3
July 7
etc.
Help me.
Closest you'll get without manually inserting idate('m') with every new record and without using fancy mysql... is by using mysql default TIMESTAMP field. Check this out:
http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html
But this a date so you'll need to use MONTH(Field) to get the month.
Related
I'm in the planning stages of creating a historical database. I will be using PHP, MYSQL and JavaScript for the website.
Often someone will know what year a person was born or picture was taken, but not the month or the day.
Is it possible for a PHP DATE variable and MYSQL DATE to be:
1920-00-00 or 1845-12-00 ?
If not, unless someone has a better idea, I'll have to create a column for year, another column for month, and yet another for day then do a bunch of value checking and combining.
Thoughts?
Thanks.
You need exakt dates for using date in mysql, so you probably have to bite down and filter everything for validating and then some code to combine it.
Is It Possible To Change MySQL Table Column Based On Date Using PHP
For Example
I Want To Change yearsold = 19 to yearsold = 20 After 1 Year
So When It Reach 2016 yearsold become 20
Thanks :D
EDIT: I Need It To Work Automatically not Having To Visit The Page Over and Over
You could do 1 of 2 things. First would be save the birthdate and calculate it every time you load the object.
The second would be to create a view that calculates the age as a column in the view, so that every time you select from the view the age is "updated" and displayed correctly. You can check out the documentation for mysql views here.
I'm new to MySQL and PHP but was wondering if someone could help me with a little project I'm doing for my boss.
I have a SQL database (MyDB) and a table in there (mytable) with two columns - the first column (index) is an auto-incrementing integer from 1-10, the second column (date) has different dates and timestamps in the format of Year-month-day time 2013-04-12 1326
I'm trying to create a simple PHP page that first gets the current date (easy enough) then looks at the table and shows the number of rows that fall within yesterday's date. For example, if I have 3 rows with 2013-04-11 XXXX and 2 rows with 2013-04-12 XXXX (and today is the 12th April 2013) the page will display 3. (The time is not important but we can't remove it from the table as it's auto created by one of the other staff's programs and he refuses to change it).
So far I've got my php page, done a connection to the DB and defined two variables:
$startdate = date('Y'."-".'n'."-".'d'." "."0000");
$enddate = date('Y'."-".'n'."-".'d'." "."2359");
As the timestamp doesn't matter I've gone for the min/max possible on the variables. I realise this will only give the current date, trying to work out how to get it to display the previous day as the date in the variable.
Now I'm trying to create a sql query that will count the number of rows where the date field falls within the startdate and enddate variables (-1 day) but not too sure where to start or how this would look. I then need to output this as a variable in PHP so I can echo it later in the page.
Anyone able to point me in the right direction? Hope any of this makes sense.
You could write a query with no params to do this (if its always just yesterday).
SELECT * FROM <table>
WHERE DATE_FORMAT(<date column>,'%j-%Y') = DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 DAY), '%j-%Y');
Date functions in the where clause might not be super awesome performance wise
i'm new to databases. I have just created my first database, so far so good. Now I looking to add time in to this.
I have certain table, when it's displayed I need it to show the table info + the date that info was added. Also possible the difference in between (5day 5hours ago) or something of the sort.
Do i need to add another column to the data table where the time will be stored? If so is there a way to auto increment that to current date? How do I go about doing that?
Not really sure where to start can someone please point me in the right direction perhaps a tutorial somewhere? Cant seem to find anything solid on this topic
Thanks a bunch!:)
For each record in your DB, you want to know when it has been created?
You have to add a column of type "timestamp". You can then set the default to "current_timestamp".
Note also that you can use the "on update current_timestamp". Instead of saving current time on insertion, it will do so each time your record is updated.
If you need the 2 dates (created_at and updated_at), you'll need 2 columns. EDIT : well you can't :p
There is a datetime as well as a timestamp field. If you use a timestamp field you can have the field automatically populate with the timestamp of when the row was inserted.
http://dev.mysql.com/doc/refman/5.0/en/datetime.html
http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html
I suggest trying out http://sqlzoo.net/ for a gentle introduction to SQL.
I'm totally new to php & mysql,
When I'm creating one trial application using php ,there is problem specify below,
I want to hide the details of record (of database) from user when date will be expired using php ,
When one user logedin & create one record entry that time automatically current date is also entered in database, but I want to give 1 week expiry date, after that the record will be not shown to the front end but it available in database. When the creator of this record renew this recod that time automatically date should be updated at current date, & same record will be shown as new entry
PLz help me,
I'm waiting for ur answer,
Thanks in advance.
What kind of column is the date one? Timestamp? or timedate?
Either way, you can do it like so (depending on your column type)
For timedate:
WHERE (date + INTERVAL 1 WEEK) < CURDATE()
For timestamp:
WHERE (timestamp + 604800) < UNIX_TIMESTAMP()
Let me know what you are using for your date column and I can update. You can also see the MySQL date functions here.