I am pulling data out of a SQL server using pyodbc. The issue is I need to pull data from a certain date frame, however; the date comes across in both an incorrect data type and format. Float64 and 90502(5/02/09 is what I would like.) I am very new to python and far from really even being very good at this and would appreciate any help.

I have tried converting to string, and then strptime but it tells me that the data is in the wrong format. I have also tried the included code, however it does not seem to do what I would like for it to do, as the data still reads as float64, and does not output as desired.

```
import pandas.io.sql as psql
from datetime import datetime
import xlwt
import numpy
date = datetime.strftime(datetime.now(), '%m.%d.%Y')

cnxn = pyodbc.connect(
    driver='{SQL Server}',
    Server='atlmktsql06',
    Database='Repository',
    trusted_connection='yes')
cursor = cnxn.cursor()
sql = ("""select * FROM dbo.tblAS400_Vcresrv WHERE VRRESV='CCVNQ'""")
df = psql.read_sql_query(sql, cnxn)
cnxn.close()
psql.to_datetime(psql.Series(['VRIN']).astype(str), infer_datetime_format=True, errors='coerce')
a = df.head(60)
print(a)
print(df.dtypes)
df.to_excel(r'C:\PythonCode\Testing.xls')

```

The end result as stated above would be for the data to convert to date, and also read appropriately so I can use the sql statement in python to pull by timeframe. Currently, VRIN = Float64 and reads as 90502 and I want VRIN = Date 5/02/09. Thank you again!
['https://Stackoverflow.com/questions/56685913', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8112192/']
I think what you want is to simply make a copy when doing case 1. 

```
aggregate_mtcars <- copy(mtcars_copy)[, eval(new_col) := sum(carb)]

```

That retains `mtcars_copy` as a separate dataset to the new `aggregate_metcars`, without the new columns.
The reason is because case 2 uses `data.frame` way to create column in a data frame (as a new list).
There is hidden parameter in data.table : `with` that handles the way the object is returned. It can be a data.table or a vector.

> 
> ?data.table :  
> 
>  By default with=TRUE and j is evaluated within the frame of x; column names can be used as variables. In case of overlapping variables names inside dataset and in parent scope you can use double dot prefix ..cols to explicitly refer to 'cols variable parent scope and not from your dataset.
> 
> 
> When j is a character vector of column names, a numeric vector of column positions to select or of the form startcol:endcol, and the value returned is always a data.table. with=FALSE is not necessary anymore to select columns dynamically. Note that x[, cols] is equivalent to x[, ..cols] and to x[, cols, with=FALSE] and to x[, .SD, .SDcols=cols].
> 
> 
> 

```r
# Case 2 :
aggregate_mtcars<-mtcars_copy[,(get(new_col)=sum(carb))] # error
aggregate_mtcars<-mtcars_copy[,eval(new_col)=sum(carb))] # error
aggregate_mtcars<-mtcars_copy[,c(eval(new_col)=sum(carb))] # Error

mtcars_copy[, new_col, with = FALSE ] # gives a data.table
mtcars_copy[, eval(new_col), with = FALSE ] # this works and create a data.table
mtcars_copy[, eval(new_col), with = TRUE ] # the default that is used here with error
mtcars_copy[, get(new_col), with = TRUE ] # works and gives a vector

# Case 2 solution : affecting values the data.frame way
mtcars_copy[, eval(new_col) ] <- sum(mtcars_copy$carb) # or any vector
mtcars_copy[[eval(new_col)]] <- sum(mtcars_copy$carb) # or any vector

```