473,506 Members | 16,994 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1900
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
12876
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
3594
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
1697
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
3581
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
28254
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
15305
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
1995
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
2386
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
3016
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
1256
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
7307
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,...
1
7021
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...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.