// you’re reading...

CMS

Date decoding/encoding


Taken from the RQL Documentation regarding Date Conversion:

In CMS, date information is always given as a floating point number or as an integer. A floating point number includes that date and time, whereas the integer only contains the date.

Here is how you convert a number into a date.

The simplest way to convert a number into a date, is to use CMS objects. Bind the DecodeDate function into your source code.

Below is an example of how your code might look:


...
' From an RQL assign a value to a variable
OldDate = EinObjekt("changedate")


' Convert value by calling the DecodeDate function
' and output in both variants.
response.write "Date from attribute=" & OldDate & " --> Convert date=" & DecodeDate(OldDate)
...


Function DecodeDate(OldDate)
   Dim objIO As Object ' Define object
   Set objIO = CreateObject("RDCMSAsp.RDPageData") ' Create object
   DecodeDate = objIO.decodedate(OldDate) ' Convert number into date
End Function

Unfortunately, there is no mention on how to encode dates within the RQL manual. There are a number of RQL queries where you can pass in dates as parameters (such as Seach and Extended Search), however these dates must first be converted to a floating point number.

Although undocumented, the encodedate method is available within the RDCMSAsp.RDPageData object.

e.g.
Function EncodeDate(OldDate)
   Dim objIO As Object ' Define object
   Set objIO = CreateObject("RDCMSAsp.RDPageData") ' Create object
   EncodeDate = objIO.encodedate(OldDate) ' Convert date into a number
End Function

Check out my blog for more RedDot CMS articles.

Share and Enjoy:
  • Print
  • email
  • Twitter
  • Digg
  • Reddit
  • StumbleUpon
  • Google Bookmarks
  • del.icio.us
  • MisterWong
  • Facebook
  • LinkedIn

No related posts.

About the author:

Kim Dezen Kim Dezen is a Senior RedDot CMS (Open Text Web Solutions) CMS Consultant, Developer and Freelancer. Part time DJ and obsessed music / vinyl junkie. Follow me on Twitter: @kimdezen                  Check out my blog: http://www.kimdezen.com for all things related to Red Dot, SEO/SEM and Web Development.

Discussion

5 comments for “Date decoding/encoding”

  1. In .Net, you can use the methods DateTime.ToOADate or DateTime.FromOADate

    Posted by RustyLogic | May 21, 2009, 1:20 pm
  2. and for those who are interested here is how it works in PHP as well:

    $objIO = new COM(”RDCMSAsp.RDPageData”) or die(”Unable to instantiate RDPageData”);

    $objIO->decodedate((string));
    $objIO->decodedate((string));

    Posted by Matthias von Deetzen | July 23, 2009, 3:04 pm
  3. Here is Javascript to convert to date YYYY-mm-dd, I’m trying to properly convert time:

    function convertToDate(floatNum)
    {
    var strOut = “”;
    var days = (”" + floatNum);
    if(days == 0)
    return strOut;

    if(days.indexOf(”.”) > 0)
    days = days.substring(0, days.indexOf(”.”));

    days = parseInt(days, 10);

    var d = new Date();
    d.setFullYear(1899,11,30);
    d.setDate(d.getDate() + days);

    strOut = d.getFullYear() + “-”;
    if((d.getMonth() + 1) < 10)
    strOut += "0";
    strOut += (d.getMonth() + 1) + "-";
    if(d.getDate() < 10)
    strOut += "0";
    strOut += d.getDate();
    return strOut;
    }

    Posted by Vitaliy Rabotnik | February 8, 2010, 5:47 pm
  4. Here’s a JavaScript function to do it:

    // returns a JavaScript Date object
    function ConvertRedDotDate (reddotDate) {
    var days = Math.floor(reddotDate);
    var seconds = Math.round((reddotDate – days) * 86400);

    var base = new Date(1899, 11, 30, 0, 0, 0, 0);

    base.setDate(base.getDate() + days);
    base.setSeconds(base.getSeconds() + seconds);

    return base;
    }

    Hope this helps

    Posted by Sam | January 23, 2011, 4:52 pm
  5. Want to add the conversion routines I use within the jRQL class ReddotDate.
    see http://jrql.110mb.com/com/hlcl/rql/as/ReddotDate.html

    // Wandelt man den 1970-01-01 00:00:00 in ein Microsoft Float Datum erhält
    // man 25569
    private final static double cFirstMSDayInDouble = 25569d;

    // nach Java ist 1970-01-01 00:00:00 die nullte Millisekunde
    // Microsoft hat hier aber schon die 2209161600000 Millisekunde
    private final static double cFirstMSDayInMilliSec = 2209161600000d;

    // eine natürliche Konstante, die Millisekunden eines Tages
    private final static double cMSecondsPerDay = 86400000d;

    ==>RedDot double value to Java milliseconds
    /**
    * ReddotDate constructor comment.
    *
    * @param msDate
    * a timestamp in the Microsoft format used by RedDot
    */
    public ReddotDate(double msDate) {
    super(Math.round((msDate – cFirstMSDayInDouble) * cMSecondsPerDay));
    }

    ==>Java date to RedDot double value
    /**
    * Liefert das Datum konvertiert in das von RedDot genutzte Microsoft float Format.
    */
    public double toMsDouble() {
    /*
    * // for day round to values without fraction final double ten =
    * 10000000000d; double time = new Long(getTime()).doubleValue();
    * //return Math.round((time + cFirstMSDayInMilliSec) / cMSecondsPerDay *
    * ten) / ten; return Math.round((time + cFirstMSDayInMilliSec) /
    * cMSecondsPerDay);
    */

    BigDecimal bd = new BigDecimal((getTime() + cFirstMSDayInMilliSec) / cMSecondsPerDay);
    return bd.setScale(10, BigDecimal.ROUND_CEILING).doubleValue();
    }

    Posted by Frank Leja | January 31, 2011, 11:13 am

Post a comment



Stay up to date! - Get notified about followup comments

If you don't feel the urge to comment but wish to stay in the loop:
Just enter your email and subscribe to new comments.

Subscribe without commenting

Recent Tweets

  • RT @AirKraft: Transport Canada breakout: they manage 80K pages and 300K assets with WSM(RedDot). Wow! #OTCW 2010-11-11
  • The RedDot usergroup session 'Future of WCM' is in National Harbor 7, now. See you there! #otcw 2010-11-11
  • RT @yttergren: @AirKraft: Calling all WSM(RedDot) devs: share your solutions on http://bit.ly/bgPIof EVERY solution can win an iPad #OTCW 2010-11-10
  • Come to the Solution Exchange session. Enhance your (#reddot) CMS project! Chesapeake 12, 3:20pm #otcw Looking forward to see you there! 2010-11-10
  • More updates...