473,395 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Date to long

Kit
hello

How to get a long value from date and vice versa .
Explanation with a code will be appreciated

Thank
Kit
Jul 21 '05 #1
10 1896
Hi Kit,

In J# code?

Cor
Jul 21 '05 #2
Hi Kit,

In J# code?

Cor
Jul 21 '05 #3
A little bit of extra explanation would be welcome.

1)How should the long look ? There are dozens of ways to represent a date by
a long : ddmmyyyy, mmddyyyy, ..., julian date, ... depending on what you
want to do with it (just representing, calculations, ...)
2)What language are you using ?

Somehow i get the distinct feeling that this might be homework.

Yves

"Kit" <an*******@discussions.microsoft.com> schreef in bericht
news:34**********************************@microsof t.com...
hello

How to get a long value from date and vice versa .
Explanation with a code will be appreciated.

Thanks
Kit

Jul 21 '05 #4
A little bit of extra explanation would be welcome.

1)How should the long look ? There are dozens of ways to represent a date by
a long : ddmmyyyy, mmddyyyy, ..., julian date, ... depending on what you
want to do with it (just representing, calculations, ...)
2)What language are you using ?

Somehow i get the distinct feeling that this might be homework.

Yves

"Kit" <an*******@discussions.microsoft.com> schreef in bericht
news:34**********************************@microsof t.com...
hello

How to get a long value from date and vice versa .
Explanation with a code will be appreciated.

Thanks
Kit

Jul 21 '05 #5
Kit
Thanks for ur reply

I'm using C# , i want date in all the possible formats(MM/DD/YYYY ....

Thanks in advance
Jul 21 '05 #6
Kit
Thanks for ur reply

I'm using C# , i want date in all the possible formats(MM/DD/YYYY ....

Thanks in advance
Jul 21 '05 #7
Kit <an*******@discussions.microsoft.com> wrote:
I'm using C# , i want date in all the possible formats(MM/DD/YYYY ....)


Look up "date and time format strings" in the MSDN index.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #8
Kit <an*******@discussions.microsoft.com> wrote:
I'm using C# , i want date in all the possible formats(MM/DD/YYYY ....)


Look up "date and time format strings" in the MSDN index.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #9
For the MM / DD / YY format :

public static long DateToLong(DateTime date) {
return date.Month * 1000000 + date.Day * 10000 + date.Year;
}
public static DateTime LongToDate(long date_as_long) {
return new DateTime((int) date_as_long % 10000, (int) date_as_long /
1000000, (int) (date_as_long / 10000) % 100);
}

Example :

Console.WriteLine("{0}", DateToLong(new DateTime(2004,4,28)));
Console.WriteLine("{0}", LongToDate(04282004).ToShortDateString());

The others will be very similar, you will only have to change the
calculations a bit depending on the position you want the different parts of
the date in the long.

Yves

"Kit" <an*******@discussions.microsoft.com> schreef in bericht
news:E0**********************************@microsof t.com...
Thanks for ur reply

I'm using C# , i want date in all the possible formats(MM/DD/YYYY ....)

Thanks in advance

Jul 21 '05 #10
For the MM / DD / YY format :

public static long DateToLong(DateTime date) {
return date.Month * 1000000 + date.Day * 10000 + date.Year;
}
public static DateTime LongToDate(long date_as_long) {
return new DateTime((int) date_as_long % 10000, (int) date_as_long /
1000000, (int) (date_as_long / 10000) % 100);
}

Example :

Console.WriteLine("{0}", DateToLong(new DateTime(2004,4,28)));
Console.WriteLine("{0}", LongToDate(04282004).ToShortDateString());

The others will be very similar, you will only have to change the
calculations a bit depending on the position you want the different parts of
the date in the long.

Yves

"Kit" <an*******@discussions.microsoft.com> schreef in bericht
news:E0**********************************@microsof t.com...
Thanks for ur reply

I'm using C# , i want date in all the possible formats(MM/DD/YYYY ....)

Thanks in advance

Jul 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chopper | last post by:
I realise this question has been raised many times but I am still no wiser as to why setting the locales will not work in my ASP application. I have searched on google groups etc. and tried...
1
by: Num | last post by:
Hi all, I have to convert a J2EE date as a long ("Millis") in a .NET date as a long ("Ticks") In Java, currentTimeMillis, is the difference, measured in milliseconds, between the current time...
0
by: UBI | last post by:
Vorrei suggerire una funzione completa per la differenza fra due date. (questo è codice freeware, niente di illegale) La funzione seguente permette il calcolo di una differenza precisa tra due...
1
by: Riley DeWiley | last post by:
I have an UPDATE query that is always setting 0 records. When I cut and paste the SQL into Access and use it, it fails in the same way unless I coerce the date fields to be '=now()', in which case...
5
by: Bryan Yeo | last post by:
Trying to get the user password expire date from AD, but there is no such field. What I could get is the PasswordLastChanged property. Is there anyway I could calculate the date or something? ...
2
by: - Steve - | last post by:
I'm taking the value of the expire date out of an AD account (accountExpires attribute) and passing it into this function. static DateTime LargeIntToDateTime(ActiveDs.LargeInteger li) { long...
3
by: yxq | last post by:
Hello, The XP Desktop clean wizard can get the last access time of desktop shortcut, i found that the info come from ...
5
by: Donkey | last post by:
Hello, I want to find out how many digits does each date type have and how many bytes does it occupy in memory, so I wrote a program below: #include <stdio.h> const long double...
1
by: JonathanParker | last post by:
Another quick one! Trying to search for records by both accounting period and by year in two seperate queries actioned by option buttons. I've sorted the formatting so it's in a UK format but I...
0
by: Wolfgrin | last post by:
Hi, I have set up a report In Access 2003 where there are 2 check boxes I refer to to change the color of the Date of that record. That part is working. I also need to Change the color of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.