Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7935237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:51:38+00:00 2026-06-03T21:51:38+00:00

I am in the process of re-developing an application that was started in PHP

  • 0

I am in the process of “re-developing” an application that was started in PHP sometime ago. The developer involved has left the company quite awhile ago and all efforts to contact him have fallen to the wayside.

I do not need help converting the whole site as its quite a simple application. However we are integrating with an API service (who’s documentation is rather poor) and I am having problems understanding their dateTime strings.

Here is the excerpt (the only bit) on how they use there datetimes.

”
The datetime is expressed as a number derived from an algorithm using the day month year hour minutes and seconds as follows:

date=year<<20; 
date|=month<<16; 
date|=day<<11; 
date|=hour<<6;
date|=minute; 

To unpack the date from a given number is as follows:

year=(date & 0xfff00000) >> 20;
month=(date & 0x000f0000) >> 16;
day=(date & 0x0000f800) >> 11; 
hour=(date & 0x000007c0) >> 6; 
minute=(date & 0x0000003f);

“

Now comes my question. The developer (and this is a working example) has created the following PHP Function that converts a timestamp to the required format. I am unsure if bitwise timestamp is a “generic algorithm”.

I have tried looking around and couldnt find anything.

/**
 * Converts a unixtime stamp to a bitwise timestamp
 * 
 * @access public
 * @param mixed $unixtime
 * @return void
 */
function convert_unixtime_to_bitwise($unixtime)
{
    /*$year = date('Y', $unixtime);
    $month = date('m', $unixtime);
    $day = date('j', $unixtime);
    $hour = date('G', $unixtime);
    $min = date('i', $unixtime);*/

        $year = date('Y', $unixtime);
    $month = date('m', $unixtime);
    $day = date('j', $unixtime);
    $hour = date('G', $unixtime);
    $min = date('i', $unixtime);

    $date = 0;
    $date = $year << 20;
    $date |= $month << 16;
    $date |= $day <<11;
    $date |= $hour <<6;
    $date |= $min;

    return $date;
}

/**
 * Converts a bitwise datestamp to a standard unixtime stamp
 * 
 * @access public
 * @param mixed $timestamp
 * @return void
 */
function convert_bitwise_to_unixtime($timestamp)
{
    $dateline = array();

    $dateline['year'] = ($timestamp & 0xfff00000) >> 20;
    $dateline['month'] =($timestamp & 0x000f0000) >> 16;
    $dateline['day'] = ($timestamp & 0x0000f800) >> 11;
    $dateline['hour'] = ($timestamp & 0x000007c0) >> 6;
    $dateline['min'] = ($timestamp & 0x0000003f);

    return mktime($dateline['hour'], $dateline['min'], 0, $dateline['month'], $dateline['day'], $dateline['year']);
}

Can anyone help me convert this to .Net in the simplest of fashions. Ideally i would write an extension method to the datetime object to return a “bitwise?” object and an extension methods to turn a bitwise timestamp into a datetime timestamp. I would ideally end up with something similar to bel..

public static class Extensions
{
    public static BitWiseDateStamp ToBitWiseDateStamp(this DateTime timeStamp)
    {
        return BitWiseDateStamp.New(timeStamp);
    }

}

public class BitWiseDateStamp
{
    private string _value;

    public string Value
    {
        get { return _value; }
        set { _value = value; }
    }


    public static BitWiseDateStamp New(DateTime date)
    {
        var b = new BitWiseDateStamp();

        var bitWiseStr = string.Empty; 

        //= Convert to bitwise string format...

        b.Value = bitWiseStr;
        return b;
    }

    public override string ToString()
    {
        return this._value;
    }

    public DateTime ToDateTime()
    {
        var date = DateTime.MinValue;
        var dateStr = string.Empty;

        //== Convert bitwise string to date string respresenation

        DateTime.TryParse(dateStr, out date);
        return date;
    }
}

I really appreciate any help anyone can provide.

Cheers,

Nico

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:51:40+00:00Added an answer on June 3, 2026 at 9:51 pm

    Perhaps I’m missing something, but won’t this do?

    public class BitwiseDateStamp
    {
        private readonly int _value;
    
        public BitwiseDateStamp(DateTime dt)
        {
            this._value = dt.Year << 20;
            this._value |= dt.Month << 16;
            this._value |= dt.Day << 11;
            this._value |= dt.Hour << 6;
            this._value |= dt.Minute;
        }
    
        public BitwiseDateStamp() : this(DateTime.Now)
        {   
        }
    
        public DateTime ToDateTime()
        {
            int year = this._value >> 20;
            int month = (this._value & 0x000f0000) >> 16;
            int day = (this._value & 0x0000f800) >> 11;
            int hour = (this._value & 0x000007c0) >> 6;
            int minute = this._value & 0x0000003f;
    
            return new DateTime(year, month, day, hour, minute, 0);
        }
    
        public override string ToString()
        {
            return this._value.ToString();
        }
    }
    

    and

    public static class DateTimeExtensions
    {
        public static BitwiseDateStamp ToBitwiseDateStamp(this DateTime dt)
        {
            return new BitwiseDateStamp(dt);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently in the process of developing a GWT 1.7.1 application that deals with
In our application through the process of developing a lot of JAR files has
I'm in the process of developing a .NET application that needs to be able
I am in the process of developing a desktop application that needs a database.
I am currently in the process of developing a canvas application that will make
I’m in the process of developing pretty basic web application, that is mostly so
My company has recently started developing custom iPhone applications for various clients. One of
I am in the process of developing a web application that consists visually of
I'm in the process of developing an application that uses client side code (js
I'm developing an WPF application that has an reference of a C# Class Library.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.