Jump to content

Recommended Posts

I have a field in my database where the user will put a date in a form in the following format:

 

DD/MM/YY

 

I will then want to perform calculations on this field against today's date and output the number of days past the date entered.

 

What field type should I choose? and what would be the default value?

 

Also, when wanting to store a large amount of text in a db, again what type should be used?

Link to comment
https://forums.phpfreaks.com/topic/137580-user-date-input/
Share on other sites

Ill give you a basic example. For this example we will assume you have an int(11) field in the database named date_entered.

 

Where you will enter the data.

<?php

$date = time();

$query = "INSERT INTO table (date_entered) VALUES ('$date')";

mysql_query($query);

 

Basically that will put something like "123092434" in the database. That is actually the number of seconds since 1900 or something like that (irrelevant).

 

Then when you pull the data you will do it like this:

<?php
//obviously this is after you have queried for the results
$date_entered = date("m/d/y", $row['date_enterd'])  //this would format it like 12/18/08

 

Hopefully that is understandable

Link to comment
https://forums.phpfreaks.com/topic/137580-user-date-input/#findComment-719095
Share on other sites

If you wanted to get the last days results you would do something like this:

 

<?php
$one_day = 60*60*24; //60 seconds times 60 minutes times 24 hours 1 day if you needed more days you would just multiply that times the number of days

$results = $row['date_entered'] - $one_day;

$query = "SELECT * FROM table WHERE date_entered >= '$results'";

 

Again this is just for demonstration purposes.

Link to comment
https://forums.phpfreaks.com/topic/137580-user-date-input/#findComment-719099
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.