Jump to content

Date insert problem

- - - - -

  • Please log in to reply
9 replies to this topic

#1
Hamed

Hamed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
 if($db->readQuery("INSERT INTO `test` (`testID` ,`title` ,`testDes` ,`creditPerTure` ,`negPerFalse` ,`total` ,`neededCredit` ,`testPassword` ,`startDate` ,`endDate` ,`time` ,`testNum`) VALUES (NULL , '$title', '$des', '$cPT', '$nPF', '$total', '$need', '$testpass', '$sdate', '$edate', '$time', '$num');"))

'$sdate' and '$edate', are date and after I insert them into database I get 0000-00-00 (my date format is yyyy-dd-mm)

#2
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
I would need to see more of your code to give you an accurate answer. Also you should make sure the date variables are formed ocrrectly in PHP to fit the criteria of the date in SQL

example :

$date = date('Y-m-d');


would give it yyyy-mm-dd

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#3
Hamed

Hamed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
I get date in date format with POST method!

#4
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Well then, post up your code. You must be doing something wrong somewhere else.

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#5
Hamed

Hamed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
    if($_GET['submit'] == 'addtest')
    {
        $title = $_POST['title'];
        $des = $_POST['des'];
        $testpass = $_POST['testpass'];
        $cPT = intval($_POST['cPT']);
        $nPF =intval( $_POST['nPF']);
        $total = intval($_POST['total']);
        $need = intval($_POST['need']);
        $sdate = $_POST['sdate'];
        $edate = $_POST['edate'];
        $num = intval($_POST['num']);
        $time = intval($_POST['time']);
        if($db->readQuery("INSERT INTO `test` (`testID` ,`title` ,`testDes` ,`creditPerTure` ,`negPerFalse` ,`total` ,`neededCredit` ,`testPassword` ,`startDate` ,`endDate` ,`time` ,`testNum`) VALUES (NULL , '$title', '$des', '$cPT', '$nPF', '$total', '$need', '$testpass', '$sdate', '$edate', '$time', '$num');"))
        {
            $tid = $db->insertID();
            Func::showMsg($Lang->getVar('test.added'),'./test.php?form=addC&tid='.$tid.'&num='.$num,4);
        }

This is my code!

#6
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
    if($_GET['submit'] == 'addtest')
    {

Should that be $_GET, or $_POST ?

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#7
Hamed

Hamed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
$_GET['submit'] is right!!
If you help me in http://forum.codecal...dd-reverse.html
I don't need date in this format!

#8
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Why dont you just change the field type to varchar?

:D You should rep+ me so that I can win :D

My Blog | Ask me!
Error : Satan did it

#9
Hamed

Hamed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
Look,
I want to have date in bigint like vBulletin or any other programs.
They save date in bigint number and they convert it to yyyy-mm-dd as they need.
Now I want to have convert yyyy-mm-dd to bigint and reverse of this function I know mkdate or other function do this job but I dont know how!!!

#10
rhossis

rhossis

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
Hi Hamed,
For example assuming
$date="2010-12-25";
- To convert date to int try strtotime($date);
- To convert back to yyyy-mm-dd format try date("Y-m-d",$date)

Did you have something like that in mind?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users