In Azure Databricks there isn't a direct equivalent to SQL Server TIMEFROMPARTS
function. However, you can achieve a similar result by using Spark SQL. Create a DataFrame similar to your table12
and insert the values.
from pyspark.sql import SparkSession
from pyspark.sql.functions import col
# Initialize Spark Session
spark = SparkSession.builder.appName("Time Conversion").getOrCreate()
# Create DataFrame
data = [("0", "620")]
df = spark.createDataFrame(data, ["col", "col1"])
Then you'll need to extract the hour and minute parts from the col1 field and then format these into a time string.
from pyspark.sql.functions import format_string
# Convert and format time
df_time = df.withColumn("hour", (col("col1").cast("int") / 100).cast("int")) \
.withColumn("minute", (col("col1").cast("int") % 100).cast("int")) \
.withColumn("formatted_time", format_string("%02d:%02d:00", "hour", "minute"))
Then, display the result.
df_time.select("formatted_time", "col1").show()