Convert MySQL timestamp field to a Unix timestamp

I have a process where I want to compare the current date with an expiration date that is so many months after a registration date. The registration date is stored in a MySQL timestamp format. I want to convert this to a Unix timestame so I can do the comparison with Time(). I have tried both the MySQL UNIX_TIMESTAMP and the PHP getTimestamp() functions and cannot get them to work. I have tried UNIX_TIMESTAMP both in  the original SELECT statement and as a stand alone one. I also get a divide-by-zero error with the date_default_timezone_set function. I have enclosed screenshots of the code and the result of the echo at the bottom. THANKS!

You're making it far too complicated.
SELECT TO_DAYS(reg_date) - TO_DAYS(CURDATE()) AS daysleft
FROM ssregis
WHERE. . .
That will give you the number of days left until the registration expires. If it's less than 0, redirect to the renewal page.
By the way, you're laying yourself wide open to SQL injection attacks by failing to escape the input from the query string. At the very least, you should be doing this:
$entered_ss_id = mysql_real_escape_string($_GET['record_id']);
$entered_email = mysql_real_escape_string($_GET['email_address']);
However, since it looks as though you're hand-coding the script, you should be using MySQL Improved rather than PHP's deprecated MySQL functions. See http://docs.php.net/manual/en/mysqlinfo.api.choosing.php.

Similar Messages

  • Converting a timestamp field from GMT to EST

    Hi
    I have to convert the timestamp field coming from the source from GMT to EST.
    CREATE TABLE X
    TS_FIELD TIMESTAMP(6)
    INSERT INTO X VALUES('07-JAN-13 02.00.06.597000 PM');
    INSERT INTO X VALUES('07-FEB-13 02.00.06.676000 PM');
    INSERT INTO X VALUES('07-MAR-13 12.36.14.260000 PM');
    INSERT INTO X VALUES('07-APR-13 12.36.56.713000 PM');
    INSERT INTO X VALUES('07-MAY-13 03.46.48.800000 AM');
    I need to convert the above timestamp field from GMT to EST in 24hour format.
    I tried it doing,but I am getting hours conflict with the day error.
    I have tried the below one and milliseconds being set to zero's
    select X,
    TO_timestamp(TO_CHAR(CAST(FROM_TZ(CAST(TO_DATE(TO_CHAR(X,'YYYY-MM-DD HH24:MI:SS.SSSSS')
    ,'YYYY-MM-DD HH24:MI:SS.SSSSS')
    AS TIMESTAMP),'GMT') AT TIME ZONE 'US/EASTERN' AS DATE),'YYYY-MM-DD HH24:MI:SS.SSSSS'),'YYYY-MM-DD HH24:MI:SS.SSSSS')
    FROM X
    Please help me in this regard.I am trying in parallel as well.
    Thanks in advance
    KVB

    Not clear what are you trying to achieve..Why are you casting as DATE?
    SQL>  select ts_field,
      2          cast(from_tz(ts_field,'GMT') AT TIME ZONE 'EST' as timestamp) t
      3   FROM X;
    TS_FIELD                                                                    T
    07-JAN-13 02.00.06.597000 PM                                                07-JAN-13 09.00.06.597000 AM
    07-FEB-13 02.00.06.676000 PM                                                07-FEB-13 09.00.06.676000 AM
    07-MAR-13 12.36.14.260000 PM                                                07-MAR-13 07.36.14.260000 AM
    07-APR-13 12.36.56.713000 PM                                                07-APR-13 07.36.56.713000 AM
    07-MAY-13 03.46.48.800000 AM                                                06-MAY-13 10.46.48.800000 PM

  • Converting sql timestamp into a usable java format??

    hi there.
    does anyone know how to convert an sql timestamp into a usable java format? i have retrieved a timestamp from a mysql table in a jsp script and would like to convert it into the following format:
    12:42pm | 08.07.02
    as i understand it, i'll need to convert the timestamp into seconds since 1970 and then manipulate it as a calendar object? my first line is working, but i don't know what to do after...
    java.sql.Timestamp sqlTimestamp = resultSet.getTimestamp("date_and_time");
    next...?
    any help would be much appreciated!!
    thanks.

    please excuse my java sytnax ignorance, but i've tried a bunch of different syntax arrangements and can't figure out how to use the getTime() method. what comes after my first line there?
    java.sql.Timestamp sqlTimestamp = resultSet.getTimestamp("date_and_time");
    then something like:
    long msec=date.getTime(sqlTimestamp);
    but that doesn't seem to work...
    thanks for any help!

  • MySQL timestamp formatting errors

    I'm continuing to have odd formatting errors when pulling data out of a MySQL database.  The one I'm currently having is with time values. 
    The screenshot shows that the error is being generated in the Variant to Data.vi  The actual time stored in the database is 8:30AM  But when converted to timestamp, I get 8:29:59.999  Unfortunately, there doesn't seem to be an easy way to 'round' this value back to what I want either.  
    I could go back to string outputs, since that particular error doesn't seem to propagate into a string.  But that messes with the rest of my application.  Going back to string output undoes a couple of days work, and leaves me with the problem of having to convert string 'time' back into timestamp that LabVIEW can understand.
    The really odd thing is that 12:30 comes out as 12:30 just fine.  I'm not sure why this would be.  Any ideas?  
    Patrick Allen
    Solved!
    Go to Solution.

    There's no difference at all.  Changing the properties of the constant doesn't seem to effect the output at all. 
    I'm trying to figure a way to convert the string back into a timestamp now via these instructions. http://zone.ni.com/reference/en-XX/help/371361B-01/glang/scan_from_string/ (example at the bottom of the page)  
    But my string out put is in the form 7/7/2009 8:30:00 AM  and there doesn't seem to be a way at all to use the scan from string tool to covert that back into a time stamp.  
    Even if I manipulate my string output to be exactly 8:30:00 AM 7/7/2009, the example and any variation I can think of simply won't work.  I always get the error that the data is not in the expected format.   
    Message Edited by pallen on 07-07-2009 12:05 PM
    Patrick Allen

  • How to convert a timestamp to date/time in CDS View?

    Dear experts,
    I would like to convert a timestamp to a date and time within a CDS view.
    This is what I tried to do:
    Cast (Cast(<timestamp> as abap.dec(8,0)) as abap.dats) as <date>
    I also thought about first converting the timestamp into a plain numerical character, then using substring and then casting it to abap.dats. Then its giving me an error that says: "dec can't be converted into numc".
    The above written code also throws an error - "function not allowed/ no cast within a cast".
    It is quite nasty not being able to write a cast within a cast - how else am i supposed to achieve a date here?
    I am looking forward to have your answers!
    Thanks and BR
    Anja

    Hi Anja,
    what you try to do is currently not possible, a feature not available in CDS views.
    Yet it surely is a feature, ABAP developers would like to see on the feature request list .
    Cheers,
      Jasmin

  • How to convert oracle timestamp to java timestamp

    Hi,
    I need to convert oracle timestamp that i got from oracle database to java timestamp.I tried to use getTimestamp() to get timestamp value from oracle, but am getting NumberFormatException.
    Could any of suggest how to convert oracle timestamp to java timestamp.

    Thanks jverd ,
    then my code will be like:
    String oracleTS="11-MAR-05 11.19.20.625 AM";
    // am looking for yyyy-MM-dd HH:mm:ss format
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd
    HH:mm:ss");           
    Timestamp javaTimestamp=Timestamp.valueOf(oracleTS);
    System.out.println("javaTimestamp----->>
    "+javaTimestamp);
    ving java.lang.NumberFormatException: For input
    string: "MAR"Well, the SimpleDateFormat has to actually match the format you're trying to parse, for one thing. Then you have to actually USE the SDF, which you didn't.
    You really haven't made it clear what you're trying to do, and it doesn't appear that you bothered to study the links I provided.
    DateFormat df = new SimpleDateFormat("dd-MMM-yy HH.mm.ss.SSS aa");
    Date date = df.parse(oracleTS);
    Timestamp ts = new Timestamp(date.getTime());

  • Anybody know of a method to convert a timestamp to a Nanosec equivalent?

    Does anybody know of a method to convert a timestamp object to a nanosecond equivalent since 1970?
    Thanks

    By a timestamp object you mean an instance of the class java.sql.Timestamp, right? Then the following will give you the nanoseconds:
    long nanos = stamp.getTime()*1000000 + stamp.getNanos();

  • How to convert normal timestamp to julian timestamp in oracle

    Hi Friends
    How can i convert normal timestamp to Julian Timestamp in Oracle ?
    Thanks for your help

    Hi Chris,
    I dont have any idea on this. But need clarification on your query.
    When I executing below query I'm getting same output. 'J' will give only Julian day right not the timestamp. Please correct me if I am wrong.
    SQL> select to_char(systimestamp,'J') J,to_char(sysdate,'J') from dual;
    J            TO_CHAR
    2456631   2456631
    http://en.wikipedia.org/wiki/Template:JULIANDAY.TIMESTAMP

  • Converting Oracle TIMESTAMP(4) column to SQL datetime column conversion error in ssis

    I could not able to convert Oracle TIMESTAMP(4) column to SQL datetime column conversion error in ssis.
    I'm connecting OLEDD Oracle Source to OLEDB SQL Destination in SSIS package. I'm trying to insert data from oracle datetime column into sql datetime column. I'm getting some errors.
    Please provide helpful info.

    You can transform the data types directly at the source by writing a proper SQL statement, or you can convert them using the data conversion component.
    Please refer the below link
    http://stackoverflow.com/questions/6256168/how-to-convert-a-timestamp-in-string-format-to-datetime-data-type-within-a-packa

  • How to convert a numeric field representing UNIX time to a standard report

    Looking for some help on the creation of a formula that will allow me to convert a numeric string which represent Unix time to a standard date format.
    Sample string value "1199149200", Jan 1 2008, 1 AM

    Hi,
    Use the DateAdd formula convert Unix epoch to normal datetime (Unix epoch = number of seconds that have elapsed since January 1, 1970).
    DateAdd("s", 1199149200, datetime("01/01/1970 00:00:00"))
    Cheers,
    Fritz

  • Issues while using Migration Workbench to convert MYSQL Database

    Please help me out to convert mysql database to oracle database. I have been trying various ways yet I hanging with certain issues.
    I have downloaded SQLDEVELOPER 1.2.2998. It required plugin mysql-connector-java-5.0.6.jar file. I specified the directory of jdbc as mysql-connector-java-5.0.6.jar file while in execution of sqldeveloper 1.2.2998. I am working in Windows xp platform. I am able to
    connect to mysql database.
    create a source mode.
    connect to new oracle database
    create migration repository
    capture the mysql database
    Issues arised are :
    Java lang Null Pointer assignment.
    further the captured data is not effected in the captured model.
    please give me soln I am online

    Hi Vishnu,
    For converting date and time into timestamp form:
      CONVERT DATE <date variable>
              TIME <time variable>
    INTO TIME STAMP <timestamp variable>
         TIME ZONE SY-ZONLO.
    After this statement, the timestmap variable contains the timestamp form of the provided date and time.
    Hope this helps.
    Regards,
    Swarna Munukoti.

  • Error when converting a numeric field to XML

    Hi,
            When i run the Adobe intractive form,i am getting following exception
    "Error when converting a numeric field to XML"
    Anyone plz suggest
    Regards,
    vinoth

    Hi Vinoth Raja,
    For resolving the following exception
    "Error when converting a numeric field to XML"
    You have to follow the below link:-
    http://www.saptechies.com/error-when-converting-numeric-field-xml/
    May be it will help you
    Regards,
    Sushma Yadav

  • How to convert the text field into currency field

    Hi,
    I have an requirement to converting the text field into currency.
    If I convert directly it gives dump.
    If I convert this to Numeric means it takes the decimals also as whole value.
    Is there any FM to convert the text field into Currency field.
    Please advice me.
    Thanks in advance.

    Hi,
    I am on an SRM sytem, which unfortunately does not have th FM: PSSV_TEXT_INTO_FIELD_CURRENCY.
    But I also need to transfer a string value like '12,99' to a field with type curr.
    Can i Do that manually, or is there another FM?
    I have already checked code with write to or pack/unpack.
    But without success yet.
    Something like this:
    DATA: g_str(11) type c.
    DATA: g_p type p.
    WRITE '12,99' TO g_str CURRENCY 'EUR'.
    is no use for me. Finally I need to move g_str to my curr-field, which causes st22.
    also: PACK g_str to <curr-field or g_p> dumps.
    Help appreciated.
    regards, matthias

  • Sending colour from a JSP page into a MySQL database field

    Dear All,
    I am working on trying to send different colours into a MySQL database field from a JSP page.
    This is so that I can represent different pieces of data on my webpage tables in different colours providing status depending on the user request.
    What is the best way to write JSP code for this?
    thanks,
    Alasdair

    Double-posted:
    http://forum.java.sun.com/thread.jspa?threadID=598637

  • How to convert a date field with format (dd,mm,yyyy) to format (mm,dd,yyyy)

    Hello.
    How to convert a date field with format (dd,mm,yyyy) to format (mm,dd,yyyy)
    I have text field which has a databind to a date field. When I click on it, we can select the date, it is added on the format (dd,mm,yyyy). When I want to insert this date field to a database It doesnu2019t allow me to do it because it will only accept date field on the format (mm,dd,yyyy)
    I tried to store this format on a date variable and I get a message saying that is impossible to convert a string into a date.
    Regards,
    Jose

    Hi Jose,
    usually you format strings in c# like
    string.Format("{0:yyyyMMdd}", insertyourstring);
    in your case
    string.Format("{0:MM/dd/yyyy}", insertyourstring);
    [look here|http://idunno.org/archive/2004/14/01/122.aspx]
    there are more details
    if everything fails split the string with Mid()
    or ask me
    lg David

Maybe you are looking for

  • Dynamic Configuration of File Adapter

    Hi, XI Version 3.0 SP13, Planning to upgrade to SP14 In my scenario I need to pick up files from 4 static locations and based on the file name and pick up type(file/ftp) I can find out the destination's connectivity information from a Cross-Referenci

  • File formatting using File adapter

    Hi we are using a sender / receiver file adapter to recive file from source and post file to the target location This is the expected format in the target system <?xml version="1.0" encoding="utf-8"?> <YYY_TIME_XML> <YYY_TIME_DATA> <CLIENTID>1</CLIEN

  • Cannot Install CS4 IM GOING CRAZY!

    Hey everyone, My problem is as follows: I cannot install any program in the CS4 Design Suite on my computer. This is not an upgrade, this is a fresh install.I know the packages are good because I installed them on my laptop with the same installers a

  • Accounting documents not generated in MIGO for Acct. ***.Category "A"

    Hi Friends, I have created a PO for Asset procurement. I have selected acct. ***. category as "A" in the PO. When I do the GR, the material document is getting generated but without any accounting document. Accounting docs are getting generated for o

  • NWDS - Build EJB Archive not possible

    Hi there! Recently I updated my NWDS from version 2.0.15 to version 2.0.16. My workspace mainly consists of 2 EJB Module projects, 1 Web Module Project and 1 Enterprise Application project. The EAR project bundles the modules to an enterprise applica