473,732 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to convert Date to int

New to C# ---- How do I convert a Date to int?

In VB6:

Dim lDate as long

lDate = CLng(Date)
In C#

int lDate;

Then what?
Thanks In Advance.
May 4 '06 #1
17 71445
Try Convert.ToInt32 (DateTime)

http://msdn2.microsoft.com/en-us/lib...t.toint32.aspx

Jeff

Terry Jolly wrote:
New to C# ---- How do I convert a Date to int?

In VB6:

Dim lDate as long

lDate = CLng(Date)
In C#

int lDate;

Then what?
Thanks In Advance.

May 4 '06 #2
It should be noted that you are going to lose the time information when
you do this (and there is no way to prevent that, either).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jeff" <ju******@jeff. net> wrote in message
news:PK******** *********@torna do.texas.rr.com ...
Try Convert.ToInt32 (DateTime)

http://msdn2.microsoft.com/en-us/lib...t.toint32.aspx

Jeff

Terry Jolly wrote:
New to C# ---- How do I convert a Date to int?

In VB6:

Dim lDate as long

lDate = CLng(Date)
In C#

int lDate;

Then what?
Thanks In Advance.

May 4 '06 #3
I get an error on compling: "Cannot implicitly convert type
'System.DateTim e' to 'int' " ----- Any other ideas?

"Jeff" <ju******@jeff. net> wrote in message
news:PK******** *********@torna do.texas.rr.com ...
Try Convert.ToInt32 (DateTime)

http://msdn2.microsoft.com/en-us/lib...t.toint32.aspx

Jeff

Terry Jolly wrote:
New to C# ---- How do I convert a Date to int?

In VB6:

Dim lDate as long

lDate = CLng(Date)
In C#

int lDate;

Then what?
Thanks In Advance.

May 4 '06 #4
It would help if you paste a snippet of your code

Terry Jolly wrote:
I get an error on compling: "Cannot implicitly convert type
'System.DateTim e' to 'int' " ----- Any other ideas?

"Jeff" <ju******@jeff. net> wrote in message
news:PK******** *********@torna do.texas.rr.com ...
Try Convert.ToInt32 (DateTime)

http://msdn2.microsoft.com/en-us/lib...t.toint32.aspx

Jeff

Terry Jolly wrote:
New to C# ---- How do I convert a Date to int?

In VB6:

Dim lDate as long

lDate = CLng(Date)
In C#

int lDate;

Then what?
Thanks In Advance.


May 4 '06 #5

"Terry Jolly" wrote...
New to C# ---- How do I convert a Date to int?

In VB6:

Dim lDate as long

lDate = CLng(Date)
In C#

int lDate;

Then what?


Well, AFAIR, a Date in VB6 was internally represented by a double, where the
fractional part represented the time of day.

In .NET a DateTime isn't the same thing, and you won't get the same integer
value.

Here a DateTime has "ticks" which is a long, representing the number of
100-nanoseconds since the epoch (which date now that was).

So, the question is rather what you want it for, and how you're going to use
it?

If it simply is to store away it as an integer value, or vice versa, you can
use the ticks, e.g.:

DateTime d = new DateTime(632820 056780400000);

long ticks = d.Ticks;

Note that it's not an int, it's a long.

// Bjorn A

May 4 '06 #6
private void button1_Click(o bject sender, EventArgs e)

{

int lDate;

lDate = Convert.ToInt32 (System.DateTim e.Now);

textBox1.Text = lDate.ToString( );

}

"Jeff" <ju******@jeff. net> wrote in message
news:Ke******** *********@torna do.texas.rr.com ...
It would help if you paste a snippet of your code

Terry Jolly wrote:
I get an error on compling: "Cannot implicitly convert type
'System.DateTim e' to 'int' " ----- Any other ideas?

"Jeff" <ju******@jeff. net> wrote in message
news:PK******** *********@torna do.texas.rr.com ...
Try Convert.ToInt32 (DateTime)

http://msdn2.microsoft.com/en-us/lib...t.toint32.aspx

Jeff

Terry Jolly wrote:
New to C# ---- How do I convert a Date to int?

In VB6:

Dim lDate as long

lDate = CLng(Date)
In C#

int lDate;

Then what?
Thanks In Advance.


May 4 '06 #7
The database i'm writing too stores dates as int32 --05/04/2006 would equal
38841. Just like MS Excel would display the a date if formated as a number
with zero decimal places.
"Jeff" <ju******@jeff. net> wrote in message
news:Ke******** *********@torna do.texas.rr.com ...
It would help if you paste a snippet of your code

Terry Jolly wrote:
I get an error on compling: "Cannot implicitly convert type
'System.DateTim e' to 'int' " ----- Any other ideas?

"Jeff" <ju******@jeff. net> wrote in message
news:PK******** *********@torna do.texas.rr.com ...
Try Convert.ToInt32 (DateTime)

http://msdn2.microsoft.com/en-us/lib...t.toint32.aspx

Jeff

Terry Jolly wrote:
New to C# ---- How do I convert a Date to int?

In VB6:

Dim lDate as long

lDate = CLng(Date)
In C#

int lDate;

Then what?
Thanks In Advance.


May 4 '06 #8

Terry,

Try:
long lDate;

lDate = (long)System.Da teTime.Now;

(OR lDate = Convert.ToInt64 (System.DateTim e.Now) )
You need a 64-bit variable in order to fit the DateTime into it.
Paul Cheetham

Terry Jolly wrote:
private void button1_Click(o bject sender, EventArgs e)

{

int lDate;

lDate = Convert.ToInt32 (System.DateTim e.Now);

textBox1.Text = lDate.ToString( );

}

"Jeff" <ju******@jeff. net> wrote in message
news:Ke******** *********@torna do.texas.rr.com ...
It would help if you paste a snippet of your code

Terry Jolly wrote:
I get an error on compling: "Cannot implicitly convert type
'System.DateTim e' to 'int' " ----- Any other ideas?

"Jeff" <ju******@jeff. net> wrote in message
news:PK******** *********@torna do.texas.rr.com ...
Try Convert.ToInt32 (DateTime)

http://msdn2.microsoft.com/en-us/lib...t.toint32.aspx

Jeff

Terry Jolly wrote:
> New to C# ---- How do I convert a Date to int?
>
> In VB6:
>
> Dim lDate as long
>
> lDate = CLng(Date)
>
>
> In C#
>
> int lDate;
>
> Then what?
>
>
> Thanks In Advance.

May 4 '06 #9

"Terry Jolly" wrote...
private void button1_Click(o bject sender, EventArgs e)
{

int lDate;

lDate = Convert.ToInt32 (System.DateTim e.Now);

textBox1.Text = lDate.ToString( );

}

That won't work. This will:

private void button1_Click(o bject sender, EventArgs e)
{
long lDate = System.DateTime .Now.Ticks;
textBox1.Text = lDate.ToString( );
}
But you still haven't explained what you need an integral value of the Date
for. That snippet doesn't make any sense...

// Bjorn A
May 4 '06 #10

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

Similar topics

0
18269
by: sumeet | last post by:
how do i convert a yyyymmdd format to yyyy,mm,dd format. also i want to know how do i get the number of days between two dates which r in the format yyyymmdd. how to convert date into unix time stamp nad back
3
9024
by: galsaba | last post by:
What would be the function to convert date to the number of date for example, 2/14/05 is 45, becuse this is the 45th day of the year. What would be the function? Where can I find info on the web about it? galsaba
2
5087
by: Franck | last post by:
Hi, 'm gettin mad about date conversion. Here is the point. Got and add-in for Excel which call functions from a web service (on a remote server) The remote server has regional settings set to "en-UK" and date to
3
5961
by: sparkle | last post by:
Hi, Does anybody know how to convert date to ticks from a dateTimePicker? What I'm using now isn't working. I'm trying to use a dateTimePicker to set an appointment in Outlook with a reminder. I need this reminder to remind the recipient 14 days in advance. I'm having problems with the ReminderMinutesBeforeStart. If I simply
1
11431
by: prabhunew2005 | last post by:
I am using postgres,php in web designing. I have to convert date entered in MM-DD-YYYY format to YYYY-MM-DD format. I have to use resulting date format in my search sql. I used todate method. But i did not get correct answer. Can you give me a solution for this? (37 minutes ago )
5
4839
by: Totto | last post by:
Hi, Is it possible to convert date to dd mon yyyy hh:mi(24h) Thanks Totto
1
23201
by: Fibre Optic | last post by:
Hello, I am looking for way to convert date i.e. "Fri Feb 23 06:13:55 EST 2007" to unix time stamp? Does any one know a library which could be help full? Regards, Fibre Optic
1
12959
by: nitinkeser | last post by:
how i convert date into specific format in asp? like in date format 'Jun 17, 2007' ?
17
31301
KalariaNitya
by: KalariaNitya | last post by:
Hello All, I want to convert Date to Hindu Calender. For e.g. today is 12th sep'2008 so convert it to bhadarvo sud baras. can anybody help me how to do that? thanking u in advanced..
1
2222
by: shivasusan | last post by:
How i can convert Date dd/mm/yy to mm/dd/yy? Pls any one help me immediately.... is very very urgent. Because i am new for asp and vbscript and javascript.
0
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9181
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
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 we have to send another system
2
2721
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.